Skip to content

Commit 0b0d0d3

Browse files
fix(core): fallback $params to empty object. Properly propagate $pending up to the root
1 parent e58f51d commit 0b0d0d3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/vuelidate/src/core.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function createComputedResult (rule, model) {
103103
* @param {Function} rule
104104
* @param {Ref<*>} model
105105
* @param {Promise<Boolean>} initResult
106-
* @param $pending
106+
* @param {Ref<Boolean>} $pending
107107
* @return {Ref<Boolean>}
108108
*/
109109
function createAsyncResult (rule, model, initResult, $pending) {
@@ -152,7 +152,7 @@ function createValidatorResult (rule, model) {
152152
const ruleResult = callRule(rule.$validator, model)
153153

154154
const $pending = ref(false)
155-
const $params = rule.$params
155+
const $params = rule.$params || {}
156156
const $invalid = isPromise(ruleResult)
157157
? createAsyncResult(
158158
rule.$validator,
@@ -219,8 +219,7 @@ function createValidationResults (rules, state, key, parentKey) {
219219
let result = {
220220
$dirty,
221221
$touch: () => { $dirty.value = true },
222-
$reset: () => { $dirty.value = false },
223-
$pending: ref(false)
222+
$reset: () => { $dirty.value = false }
224223
}
225224

226225
ruleKeys.forEach(ruleKey => {
@@ -234,6 +233,10 @@ function createValidationResults (rules, state, key, parentKey) {
234233
ruleKeys.some(ruleKey => result[ruleKey].$invalid)
235234
)
236235

236+
result.$pending = computed(() =>
237+
ruleKeys.some(ruleKey => result[ruleKey].$pending)
238+
)
239+
237240
result.$error = computed(() =>
238241
result.$invalid.value && $dirty.value
239242
)
@@ -311,6 +314,12 @@ function createMetaFields (results, nestedResults) {
311314
false
312315
)
313316

317+
const $pending = computed(() =>
318+
Object.values(nestedResults).some(r => r.$pending) ||
319+
unwrap(results.$pending) ||
320+
false
321+
)
322+
314323
const $anyDirty = computed(() =>
315324
Object.values(nestedResults).some(r => r.$dirty)
316325
)
@@ -322,7 +331,8 @@ function createMetaFields (results, nestedResults) {
322331
$errors,
323332
$invalid,
324333
$anyDirty,
325-
$error
334+
$error,
335+
$pending
326336
}
327337
}
328338

@@ -360,7 +370,6 @@ export function setValidations ({ validations, state, key, parentKey, childResul
360370

361371
// Use rules for the current state fragment and validate it
362372
const results = createValidationResults(rules, state, key, parentKey)
363-
364373
// Use nested keys to repeat the process
365374
// *WARN*: This is recursive
366375
const nestedResults = collectNestedValidationResults(nestedValidators, state, key)
@@ -372,7 +381,8 @@ export function setValidations ({ validations, state, key, parentKey, childResul
372381
$errors,
373382
$invalid,
374383
$anyDirty,
375-
$error
384+
$error,
385+
$pending
376386
} = createMetaFields(results, nestedResults)
377387

378388
const $model = computed({
@@ -403,6 +413,7 @@ export function setValidations ({ validations, state, key, parentKey, childResul
403413
$errors,
404414
$invalid,
405415
$anyDirty,
416+
$pending,
406417
...nestedResults
407418
})
408419
}

0 commit comments

Comments
 (0)