is there any way to add custom validation in vuetify-jsonschema-form vue js?

Viewed 472

I want to add a back-end custom validation to vuetify-jsonschema-form fields, I know that it's not supported. but I m asking is there any other solution to do this.

2 Answers

Vuetify is simply front-end validation so you can normally do your back-end custom validation and then return a response in REST or wathever

If you are using vuetify-jsonschema-form they don't support the backend validation they only support simple validation like required, min or max. However, you can javascript. First, before submitting the form you can call your backend validation, in case of error you can add the class CSS 'text--error' to the field containing the error :

             <v-jsonschema-form
                ref="formRef"
                :schema="schema"
                :model="model"
                :options="options"
                @change="changeFunction"
             />

const fieldName = this.$refs.jsonForm[0].$el.querySelectorAll(`[name=${nameOfField}]`)[0]
formRef.getElementsByClassName('v-messages__wrapper')[0].innerHTML = errorMesg
formRef.closest('.vjsf-property').classList.add('error--text')
Related