Skip to content

Commit

Permalink
fix(powerselect): render correct slected option for choice questions (#…
Browse files Browse the repository at this point in the history
…254)

This is not using "includes" but strict equality checking to determine
which option is selected. Without this fix, the wrong option is rendered
when one option key is contained in another option key, because
String.includes is called instead of Array.includes.
  • Loading branch information
czosel authored May 18, 2019
1 parent 6c3459a commit 837ca8c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions addon/components/cf-field/input/powerselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ export default Component.extend(ComponentQueryManager, {
"field.answer.{_valueKey,listValue,stringValue}",
function() {
const key = this.get("field.answer._valueKey");
const answers = this.get(`field.answer.${key}`);
const answer = this.get(`field.answer.${key}`);
const isSingleChoice = key === "stringValue";

if (!answers) {
if (!answer) {
return null;
}

const selection = this.choices.filter(choice => {
return answers.includes(choice.slug);
return isSingleChoice
? answer === choice.slug
: answer.includes(choice.slug);
});

return key === "stringValue" ? selection[0] : selection;
return isSingleChoice ? selection[0] : selection;
}
),

Expand Down

0 comments on commit 837ca8c

Please sign in to comment.