iview a necessary skill, form validation rules vue + iview the form form validation summary

iView form component using async-validator verifier data for verification form fields, to
Form the rules set properties, while the need to verify the property prop FormItem set to point to the corresponding field. The complete validation rules refer to open source projects async-validator. Verification methods are also supported Promise.
When we set to form a string type of field required, we can use the following rules

{Type: 'string', required: true, message: 'not empty'}

But if we enter a space will be directly validated
how to validate the input box?
Here are two methods:
Method one: Use the v-model.trim instead of v-model binding on the label when form field

E.g

<form-item label=" 姓名 " prop="name">
  <i-input v-model.trim="name" placeholder="请填写姓名" size="small">
  </i-input>
</form-item>

Using this method will trim trailing spaces directly off the data at the time of form submission is no trailing spaces, if you want to retain trailing spaces, you can use the second method.

Method 2: In the validation rules plus transform function
e.g.

{type: 'string' ,transform:value=>value?value.trim():'',required:true,message:'不能为空'}

transform function is a function of the data pre-processing (only a processed result for verification), does not change the data in a form of verification.

 

 

vue + iview check summary form in the form of     https://www.cnblogs.com/codebook/p/11332824.html

 

https://www.jianshu.com/p/7da7b06fb257

Guess you like

Origin www.cnblogs.com/qdwz/p/11497467.html