@@ -48,7 +48,7 @@ export function useField(fieldName: MaybeReactive<string>, rules: RuleExpression
4848 } ) ;
4949
5050 const runValidation = async ( ) : Promise < ValidationResult > => {
51- meta . pending . value = true ;
51+ meta . pending = true ;
5252 if ( ! form || ! form . validateSchema ) {
5353 const result = await validate ( value . value , normalizedRules . value , {
5454 name : unwrap ( fieldName ) ,
@@ -58,15 +58,15 @@ export function useField(fieldName: MaybeReactive<string>, rules: RuleExpression
5858
5959 // Must be updated regardless if a mutation is needed or not
6060 // FIXME: is this needed?
61- meta . valid . value = ! result . errors . length ;
62- meta . invalid . value = ! ! result . errors . length ;
63- meta . pending . value = false ;
61+ meta . valid = ! result . errors . length ;
62+ meta . invalid = ! ! result . errors . length ;
63+ meta . pending = false ;
6464
6565 return result ;
6666 }
6767
6868 const results = await form . validateSchema ( ) ;
69- meta . pending . value = false ;
69+ meta . pending = false ;
7070
7171 return results [ unwrap ( fieldName ) ] ;
7272 } ;
@@ -165,7 +165,7 @@ export function useField(fieldName: MaybeReactive<string>, rules: RuleExpression
165165
166166 // For each dependent field, validate it if it was validated before
167167 dependencies . value . forEach ( dep => {
168- if ( dep in form . values && meta . validated . value ) {
168+ if ( dep in form . values && meta . validated ) {
169169 runValidationWithMutation ( ) ;
170170 }
171171 } ) ;
@@ -211,17 +211,17 @@ function useValidationState(fieldName: MaybeReactive<string>, initValue: any, fo
211211 // Common input/change event handler
212212 const handleChange = ( e : Event ) => {
213213 value . value = normalizeEventValue ( e ) ;
214- meta . dirty . value = true ;
215- meta . pristine . value = false ;
214+ meta . dirty = true ;
215+ meta . pristine = false ;
216216 } ;
217217
218218 // Updates the validation state with the validation result
219219 function patch ( result : ValidationResult ) {
220220 errors . value = result . errors ;
221- meta . changed . value = initialValue !== value . value ;
222- meta . valid . value = ! result . errors . length ;
223- meta . invalid . value = ! ! result . errors . length ;
224- meta . validated . value = true ;
221+ meta . changed = initialValue !== value . value ;
222+ meta . valid = ! result . errors . length ;
223+ meta . invalid = ! ! result . errors . length ;
224+ meta . validated = true ;
225225
226226 return result ;
227227 }
@@ -261,54 +261,48 @@ function useMeta() {
261261 failed : false ,
262262 } ) ;
263263
264- const flags = reactive ( initialMeta ( ) ) ;
264+ const meta = reactive ( initialMeta ( ) ) ;
265265
266- const passed = computed ( ( ) => {
267- return flags . valid && flags . validated ;
268- } ) ;
269-
270- const failed = computed ( ( ) => {
271- return flags . invalid && flags . validated ;
266+ // FIXME: Fix computation of passed
267+ watchEffect ( ( ) => {
268+ meta . passed = meta . valid && meta . validated ;
269+ meta . failed = meta . invalid && meta . validated ;
272270 } ) ;
273271
274272 /**
275273 * Handles common onBlur meta update
276274 */
277275 const onBlur = ( ) => {
278- flags . touched = true ;
279- flags . untouched = false ;
276+ meta . touched = true ;
277+ meta . untouched = false ;
280278 } ;
281279
282280 /**
283281 * Resets the flag state
284282 */
285283 function reset ( ) {
286284 const defaults = initialMeta ( ) ;
287- Object . keys ( flags ) . forEach ( ( key : string ) => {
285+ Object . keys ( meta ) . forEach ( ( key : string ) => {
288286 // Skip these, since they are computed anyways
289- if ( key === 'passed' || key === 'failed' ) {
287+ if ( [ 'passed' , 'failed' ] . includes ( key ) ) {
290288 return ;
291289 }
292290
293- flags [ key as Flag ] = defaults [ key as Flag ] ;
291+ meta [ key as Flag ] = defaults [ key as Flag ] ;
294292 } ) ;
295293 }
296294
297295 return {
298- meta : {
299- ...toRefs ( flags ) ,
300- passed,
301- failed,
302- } ,
296+ meta,
303297 onBlur,
304298 reset,
305299 } ;
306300}
307301
308- function useAriAttrs ( fieldName : MaybeReactive < string > , meta : Record < Flag , Ref < boolean > > ) {
302+ function useAriAttrs ( fieldName : MaybeReactive < string > , meta : Record < string , boolean > ) {
309303 return computed ( ( ) => {
310304 return {
311- 'aria-invalid' : meta . failed . value ? 'true' : 'false' ,
305+ 'aria-invalid' : meta . failed ? 'true' : 'false' ,
312306 'aria-describedBy' : genFieldErrorId ( unwrap ( fieldName ) ) ,
313307 } ;
314308 } ) ;
0 commit comments