Vue-form-generator: Set Form Validator from JSON string

Created on 11 May 2017  路  4Comments  路  Source: vue-generators/vue-form-generator

For situation where the entire form schema is created from a db record, one would pass the Schema as a JSON Object.
The problem with this is that the schema.fields.validator key expects a function and not a string.

{ "type": "input", "inputType": "email", "label": "E-mail", "model": "email", "placeholder": "User's e-mail address", "validator": "VueFormGenerator.validators.email" }

Is there a workaround so that the VFM validator can eval(thePassedString)?

Great contribution BTW, and thank you.

Most helpful comment

Actually this was implemented in the last release
https://github.com/icebob/vue-form-generator/releases
This is a shorthand for VueFormGenerator.validators.string. It can be an Array of Strings too.
You have to make sure these validators are declared and present in the window object.
In this case VueFormGenerator must be assigned to the window object window.VueFormGenerator=VueFormGenerator

All 4 comments

Actually this was implemented in the last release
https://github.com/icebob/vue-form-generator/releases
This is a shorthand for VueFormGenerator.validators.string. It can be an Array of Strings too.
You have to make sure these validators are declared and present in the window object.
In this case VueFormGenerator must be assigned to the window object window.VueFormGenerator=VueFormGenerator

Thank you!, works great!

It there s simular workaround for onSubmit in the submit button types?
( https://icebob.gitbooks.io/vueformgenerator/content/fields/submit.html )

... So I can pass a string of the function I want to call "onSubmit" : "mySubmitHandler"

Sorry, but I don't want to change every functions in vfg to handle string function names. You can solve it with a custom function in your project too.

new Vue({
    data() {
        return {
            model: {...}
            schema: convertStringFuncNames(mySchema)
        }
    }
});

function convertStringFuncNames(schema) {
    ....
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gkurdej picture gkurdej  路  5Comments

jaywilburn picture jaywilburn  路  3Comments

LouWii picture LouWii  路  4Comments

lionel-bijaoui picture lionel-bijaoui  路  5Comments

miseeger picture miseeger  路  4Comments