Skip to content

Commit

Permalink
fix(select): fix promptIsSelectable in combination with targetPath (#853
Browse files Browse the repository at this point in the history
)
  • Loading branch information
velrest committed Sep 2, 2022
1 parent 100aa9e commit 526d81f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion addon/components/validated-input/types/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export default class SelectComponent extends Component {

//single select
const foundOption = options.find((item) => getValue(item) === target.value);
if (targetPath) {

// If @promptIsSelectable is set to true, foundOption in this case will be undefined.
if (targetPath && foundOption) {
return foundOption[targetPath];
}
return foundOption;
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/components/validated-input/types/select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,32 @@ module(

await select("select", ["1", "2"]);
});

test("prompt is selectable in compination with optionTargetPath, optionValuePath and optionLabelPath", async function (assert) {
assert.expect(3);
const values = [2, undefined];
this.set("options", [
{ value: 1, text: "one" },
{ value: 2, text: "two" },
]);
this.set("update", (value) => {
assert.strictEqual(value, values.shift());
});

await render(
hbs`<ValidatedInput::Types::Select
@update={{this.update}}
@options={{this.options}}
@prompt="Choose this"
@promptIsSelectable={{true}}
@optionLabelPath="text"
@optionTargetPath="value"
@optionValuePath="value" />`
);

await select("select", "2");
await select("select", "option:first-child");
assert.dom("option:first-child").hasProperty("disabled", false);
});
}
);

0 comments on commit 526d81f

Please sign in to comment.