避免在 vue-form-generator 输入中使用空格



我正在为 Vue 使用基于架构的表单生成器组件.js (vue-form-generator(

有谁知道如何通过使用trim()函数避免输入字段中的动态空白区域?

下面是一个代码示例。

通过以下方式覆盖validator方法:

validator: function(value, field, model) {
if (value) {
// if user input anything, then trim it and assign it to the model and validator value also.
// this could be devastating as the user will fill difficulties in typing space
// because as long as user type a space to write a separate word, the validator will remove this, test properly 
value = model.name = value.trim();
return VueFormGenerator.validators.string(value, field, model)
} else {
return ["This field is required"];
}
}

最新更新