@@ -8,7 +8,7 @@ function isCheckbox(element) {
88 return element . getAttribute && element . getAttribute ( 'type' ) === 'checkbox' ;
99}
1010
11- export const createForm = ( config ) => {
11+ export const createForm = config => {
1212 let initialValues = config . initialValues || { } ;
1313
1414 const validationSchema = config . validationSchema ;
@@ -31,14 +31,12 @@ export const createForm = (config) => {
3131 const isSubmitting = writable ( false ) ;
3232 const isValidating = writable ( false ) ;
3333
34- const isValid = derived ( errors , ( $errors ) => {
35- const noErrors = util
36- . getValues ( $errors )
37- . every ( ( field ) => field === NO_ERROR ) ;
34+ const isValid = derived ( errors , $errors => {
35+ const noErrors = util . getValues ( $errors ) . every ( field => field === NO_ERROR ) ;
3836 return noErrors ;
3937 } ) ;
4038
41- const modified = derived ( form , ( $form ) => {
39+ const modified = derived ( form , $form => {
4240 const object = util . assignDeep ( $form , false ) ;
4341
4442 for ( let key in $form ) {
@@ -48,14 +46,14 @@ export const createForm = (config) => {
4846 return object ;
4947 } ) ;
5048
51- const isModified = derived ( modified , ( $modified ) => {
52- return util . getValues ( $modified ) . some ( ( field ) => field === true ) ;
49+ const isModified = derived ( modified , $modified => {
50+ return util . getValues ( $modified ) . includes ( true ) ;
5351 } ) ;
5452
5553 function validateField ( field ) {
5654 return util
5755 . subscribeOnce ( form )
58- . then ( ( values ) => validateFieldValue ( field , values [ field ] ) ) ;
56+ . then ( values => validateFieldValue ( field , values [ field ] ) ) ;
5957 }
6058
6159 function validateFieldValue ( field , value ) {
@@ -67,7 +65,7 @@ export const createForm = (config) => {
6765 return validationSchema
6866 . validateAt ( field , get ( form ) )
6967 . then ( ( ) => util . update ( errors , field , '' ) )
70- . catch ( ( error ) => util . update ( errors , field , error . message ) )
68+ . catch ( error => util . update ( errors , field , error . message ) )
7169 . finally ( ( ) => {
7270 isValidating . set ( false ) ;
7371 } ) ;
@@ -77,7 +75,7 @@ export const createForm = (config) => {
7775 isValidating . set ( true ) ;
7876 return Promise . resolve ( )
7977 . then ( ( ) => validateFunction ( { [ field ] : value } ) )
80- . then ( ( errs ) =>
78+ . then ( errs =>
8179 util . update ( errors , field , ! util . isNullish ( errs ) ? errs [ field ] : '' ) ,
8280 )
8381 . finally ( ( ) => {
@@ -108,13 +106,13 @@ export const createForm = (config) => {
108106
109107 isSubmitting . set ( true ) ;
110108
111- return util . subscribeOnce ( form ) . then ( ( values ) => {
109+ return util . subscribeOnce ( form ) . then ( values => {
112110 if ( typeof validateFunction === 'function' ) {
113111 isValidating . set ( true ) ;
114112
115113 return Promise . resolve ( )
116114 . then ( ( ) => validateFunction ( values ) )
117- . then ( ( error ) => {
115+ . then ( error => {
118116 if ( util . isNullish ( error ) || util . getValues ( error ) . length === 0 ) {
119117 clearErrorsAndSubmit ( values ) ;
120118 } else {
@@ -133,11 +131,11 @@ export const createForm = (config) => {
133131 . validate ( values , { abortEarly : false } )
134132 . then ( ( ) => clearErrorsAndSubmit ( values ) )
135133 // eslint-disable-next-line unicorn/catch-error-name
136- . catch ( ( yupErrors ) => {
134+ . catch ( yupErrors => {
137135 if ( yupErrors && yupErrors . inner ) {
138136 const updatedErrors = getInitial . errors ( ) ;
139137
140- yupErrors . inner . map ( ( error ) =>
138+ yupErrors . inner . map ( error =>
141139 util . set ( updatedErrors , error . path , error . message ) ,
142140 ) ;
143141
0 commit comments