File tree 3 files changed +11
-14
lines changed
templates/components/cf-field/input
3 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,13 @@ export default Component.extend({
33
33
"config:environment"
34
34
) ;
35
35
36
- this . set ( "field.answer.value" , value ) ;
37
-
38
36
/* istanbul ignore next */
39
37
if ( environment !== "test" ) {
40
38
yield timeout ( 500 ) ;
41
39
}
42
40
41
+ this . set ( "field.answer.value" , value ) ;
42
+
43
43
yield this . field . validate . perform ( ) ;
44
44
45
45
try {
Original file line number Diff line number Diff line change 1
1
import Component from "@ember/component" ;
2
- import { get } from "@ember/object" ;
3
2
import layout from "../../../templates/components/cf-field/input/checkbox" ;
4
3
import { computed } from "@ember/object" ;
5
4
@@ -11,7 +10,6 @@ import { computed } from "@ember/object";
11
10
*/
12
11
export default Component . extend ( {
13
12
layout,
14
- tagName : "" ,
15
13
16
14
choices : computed (
17
15
"field.question.{multipleChoiceOptions,dynamicMultipleChoiceOptions}.edges" ,
@@ -25,18 +23,17 @@ export default Component.extend({
25
23
26
24
actions : {
27
25
/**
28
- * Toggle the checked state of an option and trigger saving the field.
26
+ * Update the value of the field with the slugs of the currently checked
27
+ * boxes.
29
28
*
30
- * @method toggle
31
- * @param {String } slug The slug of the changed option
32
- * @param {Boolean } checked Whether the options checkbox is checked or not
29
+ * @method update
33
30
*/
34
- toggle ( slug , checked ) {
35
- const value = get ( this , "field.answer.value" ) || [ ] ;
31
+ update ( ) {
32
+ const checkedBoxes = [
33
+ ...this . element . querySelectorAll ( "input[type=checkbox]:checked" )
34
+ ] ;
36
35
37
- this . onSave ( [
38
- ...new Set ( [ ...value , slug ] . filter ( v => v !== slug || checked ) )
39
- ] ) ;
36
+ this . onSave ( [ ...new Set ( checkedBoxes . map ( el => el . value ) ) ] ) ;
40
37
}
41
38
}
42
39
} ) ;
Original file line number Diff line number Diff line change 9
9
value ={{ option.slug }}
10
10
checked ={{ contains option.slug field.answer.value }}
11
11
disabled ={{ disabled }}
12
- onchange ={{ action ( action " toggle " option.slug ) value = " target.checked " }}
12
+ onchange ={{ action " update " }}
13
13
>
14
14
{{ option.label }}
15
15
</label >
You can’t perform that action at this time.
0 commit comments