Vue.js 避免vue表单生成器输入中出现空白
我正在为Vue.js()使用基于模式的表单生成器组件 是否有人知道如何使用Vue.js 避免vue表单生成器输入中出现空白,vue.js,Vue.js,我正在为Vue.js()使用基于模式的表单生成器组件 是否有人知道如何使用trim()函数动态避免输入字段中出现空格 通过以下方式覆盖验证程序方法: validator: function(value, field, model) { if (value) { // if user input anything, then trim it and assign it to the model and validator value also. // thi
trim()
函数动态避免输入字段中出现空格
通过以下方式覆盖
验证程序
方法:
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"];
}
}
@Phil我认为这种方式不可能与vue表单生成器组件一起使用:(感谢您的回答。我不确定这是否是我需要的。我想在用户键入时删除空格。@AlbertoRhuertas您想在提交后还是用户键入后立即删除空格?用户键入后立即删除。目前,我正在使用
onChanged
方法:newVal=newVal.replace(//g,”)尝试此操作
但我也需要直观地擦除空格。@AlbertoRhuertas我已经根据您的需要更新了代码。现在检查代码。但有一点很重要,这可能是灾难性的,因为用户会在键入空格时遇到困难,因为只要用户键入一个空格来写一个单独的单词,验证器就会删除它,并正确地进行测试