Alberto Rhuertas
Alberto Rhuertas

Reputation: 773

Avoid empty spaces in vue-form-generator inputs

I'm using the schema-based form generator component for Vue.js (vue-form-generator)

Does anyone knows how to avoid dynamically empty spaces in the input field by using the trim() function?

Here is an example of the code.

Upvotes: 0

Views: 450

Answers (1)

Rafik Farhad
Rafik Farhad

Reputation: 1202

Override validator method by this:

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"];
    }
}

Upvotes: 1

Related Questions