Reputation:
I would like to generate highly customizable input forms. From the external database I receive an object representing the structure of the required input form.
I will provide two examples
Document Example 1:
Document Example 2:
Explanation of the attributes:
Things get really tricky here.
What needs to get passed to the server?
It only expects the ID and the value from each form component. Each frontend application could solve the problem differently.
Here are some examples for dynamic input forms (the language is german but this shouldn't matter).
Implementation:
Each data object represents one input form. It creates one mask component and passes in the RESULT attribute
<template>
<form class="mask" @submit.prevent="saveMask">
<MaskItem v-for="maskItem in documentData" :key="maskItem.ID" :maskItemData="maskItem"/>
<button id="btnSave" type="submit">
Save
</button>
</form>
</template>
<script>
import MaskItem from "./maskItem.vue";
export default {
name: "mask",
components: {
MaskItem
},
props: {
documentData: Array /* The RESULT array from the document object */
},
methods: {
saveMask: function(){
// loop through all maskItems and get the ID and their value
}
}
};
</script>
The mask itself should create one input component per array item.
<template>
<div class="maskItem">
Item
</div>
</template>
<script>
export default {
name: "maskItem",
props: {
maskItemData: Object
}
};
</script>
So I know I could solve this problem using JavaScript with 3000 lines of code (or more) full of if-statements. Is there a way creating text field components, number fields, date fields, ... by the delivered datatype and setup dependencies if needed?
As I mentioned the server only expects the ID and one or more values from that component so there could be multiple solutions to solve this.
Please let me know if some information are missing!
Upvotes: 4
Views: 415
Reputation: 2204
There are multiple challenges in your task:
Suggestions:
P.S. You can search for library that already done that, or most of that
Upvotes: 1