From 526d81f25eb47f938fa2fa031d5f5e710a0386bf Mon Sep 17 00:00:00 2001 From: Jonas Cosandey Date: Fri, 2 Sep 2022 19:01:16 +0200 Subject: [PATCH] fix(select): fix promptIsSelectable in combination with targetPath (#853) --- .../validated-input/types/select.js | 4 ++- .../validated-input/types/select-test.js | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/addon/components/validated-input/types/select.js b/addon/components/validated-input/types/select.js index 9ab4c69f..8580345a 100644 --- a/addon/components/validated-input/types/select.js +++ b/addon/components/validated-input/types/select.js @@ -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; diff --git a/tests/integration/components/validated-input/types/select-test.js b/tests/integration/components/validated-input/types/select-test.js index 1fccf130..34308129 100644 --- a/tests/integration/components/validated-input/types/select-test.js +++ b/tests/integration/components/validated-input/types/select-test.js @@ -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`` + ); + + await select("select", "2"); + await select("select", "option:first-child"); + assert.dom("option:first-child").hasProperty("disabled", false); + }); } );