File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -233,5 +233,10 @@ describe('Validator', () => {
233233
234234 expect ( validator . has ( [ 'first_name' ] ) ) . toBeTruthy ( )
235235 expect ( validator . first ( [ 'first_name' ] ) ) . toEqual ( 'This fist name field is required' )
236+ expect ( validator . first ( [ 'firstName' ] ) ) . toEqual ( 'This fist name field is required' )
237+
238+ validator . clear ( [ 'first_name' ] )
239+
240+ expect ( validator . has ( [ 'firstName' ] ) ) . toBeFalsy ( )
236241 } )
237242} )
Original file line number Diff line number Diff line change @@ -63,13 +63,16 @@ class Validator {
6363 return this . has ( field ) ? this . missed ( field ) : null
6464 }
6565
66- any ( fields : string [ ] = [ ] , returnObject ?: boolean ) {
66+ any ( field : string [ ] = [ ] , returnObject ?: boolean ) {
67+ const fields = this . fields ( field )
6768 if ( returnObject ) {
6869 const errors : Record < string , any > = { }
69- if ( ! fields . length ) {
70- return { }
70+ if ( ! fields . length ) return { }
71+ for ( const f of fields ) {
72+ const val = this . get ( f )
73+ if ( ! val . length ) continue
74+ errors [ f ] = val
7175 }
72- fields . forEach ( ( key : string ) => ( errors [ key ] = this . get ( key ) ) )
7376 return errors
7477 }
7578 if ( ! fields . length ) {
@@ -102,7 +105,7 @@ class Validator {
102105
103106 clear ( field ?: string | string [ ] ) {
104107 if ( ! field ) return this . flush ( )
105- const errors = omit ( cloneDeep ( this . errors ) , field )
108+ const errors = omit ( cloneDeep ( this . errors ) , this . fields ( field ) )
106109 this . fill ( errors )
107110 }
108111
You can’t perform that action at this time.
0 commit comments