wearebraid / vue-formulate

⚡️ The easiest way to build forms with Vue.
https://vueformulate.com
MIT License
2.25k stars 245 forks source link

Dinamyc props in form schema #547

Open alfredobp opened 2 years ago

alfredobp commented 2 years ago

Hello. Is there any way to pass a list of values ​​to a type select input that comes from a request to an API rest response? Currently, I have a form like this:

` [{ "component": "h3", "children": "Migrar un sitio" },

{
    "label": "Nombre de la instalación",
    "name": "name",
    "validation": "required"
},
{
    "type": "autocomplete",
    "label": "list",
    "name": "list",
    "validation": "required",
    "label": "Search for a hosting domain",
    "options": [

{ "value": 1, "label": "xxx" }, { "value": 2, "label": "Jane Roe" }, { "value": 3, "label": "Bob Foe" }, { "value": 4, "label": "Ben Cho" } ]

}, {
    "type": "submit",
    "label": "Aplicar Migración"
}

]`

I have a custom component: autocomplete, following the official documentation.

It´s works fine, but I don't want to have to do this in the json Schema. If not pass a variable in vue.js with the data array.

"options": [{ "value": "--", "label": "---" }, { "value": "webempresa", "label": "WebEmpresa" }, { "value": "dinahosting", "label": "Dinahosting" }, { "value": "arsys", "label": "Arsys" } ],

Thanks for the help

hacknug commented 2 years ago

You should probably use a computed property that returns your schema using whatever other property has your API response with the options you want to use. This could differ depending on your current implementation of the API fetch.