Skip to content
Permalink
Browse files

fix(powerselect): render correct slected option for choice questions (#…

…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 committed May 18, 2019
1 parent 6c3459a commit 837ca8c4e8a743a515fdc8b80d79998d85e7779a
Showing with 7 additions and 4 deletions.
  1. +7 −4 addon/components/cf-field/input/powerselect.js
@@ -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;
}
),

0 comments on commit 837ca8c

Please sign in to comment.
You can’t perform that action at this time.