File tree Expand file tree Collapse file tree 4 files changed +11
-12
lines changed
packages/vee-validate/src Expand file tree Collapse file tree 4 files changed +11
-12
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' vee-validate ' : minor
3+ ---
4+
5+ "feat: allow handleBlur to run validations"
Original file line number Diff line number Diff line change @@ -161,14 +161,10 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
161161 resolveValidationTriggers ( props ) ;
162162
163163 function baseOnBlur ( e : Event ) {
164- handleBlur ( e ) ;
164+ handleBlur ( e , validateOnBlur ) ;
165165 if ( isCallable ( ctx . attrs . onBlur ) ) {
166166 ctx . attrs . onBlur ( e ) ;
167167 }
168-
169- if ( validateOnBlur ) {
170- validateField ( ) ;
171- }
172168 }
173169
174170 function baseOnInput ( e : Event | unknown ) {
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ export interface PrivateFieldContext<TValue = unknown> {
137137 handleReset ( ) : void ;
138138 validate : FieldValidator ;
139139 handleChange ( e : Event | unknown , shouldValidate ?: boolean ) : void ;
140- handleBlur ( e ?: Event ) : void ;
140+ handleBlur ( e ?: Event , shouldValidate ?: boolean ) : void ;
141141 setState ( state : Partial < FieldState < TValue > > ) : void ;
142142 setTouched ( isTouched : boolean ) : void ;
143143 setErrors ( message : string | string [ ] ) : void ;
Original file line number Diff line number Diff line change @@ -159,8 +159,11 @@ function _useField<TValue = unknown>(
159159 /**
160160 * Handles common onBlur meta update
161161 */
162- const handleBlur = ( ) => {
162+ const handleBlur = ( evt ?: unknown , shouldValidate = false ) => {
163163 meta . touched = true ;
164+ if ( shouldValidate ) {
165+ validateWithStateMutation ( ) ;
166+ }
164167 } ;
165168
166169 async function validateCurrentValue ( mode : SchemaValidationMode ) {
@@ -259,11 +262,6 @@ function _useField<TValue = unknown>(
259262
260263 function setValue ( newValue : TValue , shouldValidate = true ) {
261264 value . value = newValue ;
262- if ( ! shouldValidate ) {
263- validateValidStateOnly ( ) ;
264- return ;
265- }
266-
267265 const validateFn = shouldValidate ? validateWithStateMutation : validateValidStateOnly ;
268266 validateFn ( ) ;
269267 }
You can’t perform that action at this time.
0 commit comments