File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
runner/src/server/plugins/engine/components Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ CheckboxesField as CoreCheckboxesField
3
+ } from "../../../../../../digital-form-builder/runner/src/server/plugins/engine/components" ;
4
+ import { FormData , FormSubmissionErrors } from '@xgovformbuilder/runner/plugins/engine/types' ;
5
+
6
+ export class CheckboxesField extends CoreCheckboxesField {
7
+ getViewModel ( formData : FormData , errors : FormSubmissionErrors ) {
8
+ const viewModel = super . getViewModel ( formData , errors ) ;
9
+ // Assumes that checkbox values containing commas should be followed by a space (e.g., "Option 1, Option 2").
10
+ // Ensures consistent splitting, as list items are separated by commas without spaces.
11
+
12
+ let formDataItems = ( formData [ this . name ] ?? "" ) . split ( / , (? ! \s ) / g) ;
13
+ viewModel . items = ( viewModel . items ?? [ ] ) . map ( ( item ) => ( {
14
+ ...item ,
15
+ checked : ! ! formDataItems . find ( ( i ) => `${ item . value } ` === i ) ,
16
+ } ) ) ;
17
+
18
+ return viewModel ;
19
+ }
20
+ }
21
+
Original file line number Diff line number Diff line change 9
9
} from "../../../../../../digital-form-builder/runner/src/server/plugins/engine/components/AutocompleteField" ;
10
10
export {
11
11
CheckboxesField
12
- } from "../../../../../../digital-form-builder/runner/src/server/plugins/engine/components /CheckboxesField" ;
12
+ } from "./CheckboxesField" ;
13
13
export { ComponentBase as Component } from "./ComponentBase" ;
14
14
export { ComponentCollection } from "./ComponentCollection" ;
15
15
export { DateField } from "../../../../../../digital-form-builder/runner/src/server/plugins/engine/components/DateField" ;
You can’t perform that action at this time.
0 commit comments