vuelidate icon indicating copy to clipboard operation
vuelidate copied to clipboard

Collections validation dynamic rules

Open Eugene313 opened this issue 5 years ago • 3 comments

Hello!

I found some bug in dynamic collections rules.

Target:

I thought that if I write like this

$each: {
   Description(model) {
      if (model.Title === 7) {
         return {
            maxLength: maxLength(500),
            required,
         };
      }
      return {
        maxLength: maxLength(500),
      };
   },
}

Result:

Then i get this

$each:
   $dirty:true
   $error:true
   $invalid:true
   $params:Object
   $pending:false
   0:
      $dirty:true
      $error:true
      $invalid:true
      $params:Object
      $pending:false
      Description:
         $dirty:true
         $error:true
         $invalid:true
         $params:Object
         $pending:false
         required:false
         maxLength: true

But i get this

$each:
   $dirty:true
   $error:true
   $invalid:true
   $params:Object
   $pending:false
   0:
      $dirty:true
      $error:true
      $invalid:true
      $params:Object
      $pending:false
      Description: true     **<-- why ?**

explain to me why the function does not return an object ?

Eugene313 avatar Jul 29 '20 17:07 Eugene313

And I'm interested too!

DmitriyTymoshenko avatar Jul 29 '20 17:07 DmitriyTymoshenko

Please try to stay away from $each. It is being removed in the new version in favor of context-aware validations. This means, a parent (or any ancestor component that uses Vuelidate), will know about the errors in any nested component, including those generated dynamically in a v-for etc.

Given our limited capacity, we don’t have the required time to work on the old API.

shentao avatar Aug 14 '20 13:08 shentao

I've just run into this issue https://github.com/vuelidate/vuelidate/issues/676. Some more information about this would be awesome.

DanielAsher avatar Aug 16 '20 11:08 DanielAsher