My VUE components, including Field
and Form
, are able to dynamically render a form based on the provided data.
<template>
<form @submit="$emit('submit', $event)" >
<template v-for="(item, index) in form.elements">
<Field
v-model="value[index]"
:label="item.options.label"
:type="item.type"
/>
</template>
</form>
</template>
I am able to render a form by passing structured data.
<Form :form="formStructure" v-model="state" @submit="save()" />
By using the formStructure
object, the form elements are displayed in the specified order.
My goal is to enhance the appearance of the Form
component by adding a custom template for decoration.
<Form :form="formStructure" v-model="state" @submit="save()" >
<template >
<div class="row">
<div class="col-4"><i class="icon-user"></i> <!-- Field component will be rendered here by Form component --> </div>
<div class="col-8"><i class="icon-mail"></i> <!-- Field component will be rendered here by Form component --> </div>
</div>
<h2>A Custom Header</h2>
<div class="row">
<!-- another row with other elements-->
</div>
</template>
</Form>
The structure of the form data looks something like this:
{
"form":{
"method":"post",
"id":"formF75a1543a"
},
"elements":{
"username":{
"type":"inputtext",
"options":{
"label":"Pick a username"
}
},
"email":{
"type":"inputtext",
"options":{
"label":"Your e-mail"
}
}
}
}
What steps should I take to achieve this customization?