@@ -17,6 +17,7 @@ import type {
1717 InferActionCollectorType ,
1818 NoValueCollectorTypes ,
1919 InferNoValueCollectorType ,
20+ ValidatedBooleanCollector ,
2021 ValidatedSingleValueCollectorWithValue ,
2122 ValidatedTextCollector ,
2223 InferValueObjectCollectorType ,
@@ -45,6 +46,7 @@ import type {
4546 PollingField ,
4647 ReadOnlyField ,
4748 RedirectField ,
49+ SingleCheckboxField ,
4850 SingleSelectField ,
4951 StandardField ,
5052 ValidatedField ,
@@ -151,7 +153,7 @@ export function returnSubmitCollector(field: StandardField, idx: number) {
151153 * @returns {SingleValueCollector } The constructed SingleValueCollector object.
152154 */
153155export function returnSingleValueCollector <
154- Field extends StandardField | SingleSelectField | ValidatedField ,
156+ Field extends StandardField | SingleSelectField | ValidatedField | SingleCheckboxField ,
155157 CollectorType extends SingleValueCollectorTypes = 'SingleValueCollector' ,
156158> ( field : Field , idx : number , collectorType : CollectorType , data ?: string ) {
157159 let error = '' ;
@@ -212,10 +214,40 @@ export function returnSingleValueCollector<
212214 options : options ,
213215 } ,
214216 } as InferSingleValueCollectorType < 'SingleSelectCollector' > ;
217+ } else if ( collectorType === 'ValidatedBooleanCollector' ) {
218+ const validationArray = [ ] ;
219+ if ( 'required' in field && field . required === true ) {
220+ validationArray . push ( {
221+ type : 'required' ,
222+ message :
223+ ( 'validation' in field && field . validation ?. errorMessage ) || 'Value cannot be empty' ,
224+ rule : true ,
225+ } ) ;
226+ }
227+
228+ return {
229+ category : 'ValidatedSingleValueCollector' ,
230+ error : error || null ,
231+ type : collectorType ,
232+ id : `${ field . key } -${ idx } ` ,
233+ name : field . key ,
234+ input : {
235+ key : field . key ,
236+ value : false ,
237+ type : field . type ,
238+ validation : validationArray ,
239+ } ,
240+ output : {
241+ key : field . key ,
242+ label : field . label ,
243+ type : field . type ,
244+ value : false ,
245+ } ,
246+ } as ValidatedSingleValueCollectorWithValue < 'ValidatedBooleanCollector' > ;
215247 } else if ( 'validation' in field || 'required' in field ) {
216248 const validationArray = [ ] ;
217249
218- if ( 'validation' in field ) {
250+ if ( 'validation' in field && field . validation && 'regex' in field . validation ) {
219251 validationArray . push ( {
220252 type : 'regex' ,
221253 message : field . validation ?. errorMessage || '' ,
@@ -464,6 +496,16 @@ export function returnSingleSelectCollector(field: SingleSelectField, idx: numbe
464496 return returnSingleValueCollector ( field , idx , 'SingleSelectCollector' , data ) ;
465497}
466498
499+ /**
500+ * @function returnValidatedBooleanCollector - Creates a ValidatedBooleanCollector object based on the provided field and index.
501+ * @param {SingleCheckboxField } field - The field object containing key, label, type, required, and validation.
502+ * @param {number } idx - The index to be used in the id of the ValidatedBooleanCollector.
503+ * @returns {ValidatedBooleanCollector } The constructed ValidatedBooleanCollector object.
504+ */
505+ export function returnValidatedBooleanCollector ( field : SingleCheckboxField , idx : number ) {
506+ return returnSingleValueCollector ( field , idx , 'ValidatedBooleanCollector' ) ;
507+ }
508+
467509/**
468510 * @function returnProtectCollector - Creates a ProtectCollector object based on the provided field and index.
469511 * @param {DaVinciField } field - The field object containing key, label, type, and links.
@@ -846,7 +888,12 @@ export function returnAgreementCollector(field: AgreementField, idx: number): Ag
846888 * @returns {function } - A "validator" function that validates the input value
847889 */
848890export function returnValidator (
849- collector : ValidatedTextCollector | ObjectValueCollectors | MultiValueCollectors | AutoCollectors ,
891+ collector :
892+ | ValidatedTextCollector
893+ | ValidatedBooleanCollector
894+ | ObjectValueCollectors
895+ | MultiValueCollectors
896+ | AutoCollectors ,
850897) {
851898 const rules = collector . input . validation ;
852899 return ( value : string | string [ ] | Record < string , unknown > ) => {
0 commit comments