Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): fix promptIsSelectable in combination with targetPath #853

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}
);