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:
- ID => The ID of that input field
- Value => The value of that input field and the default initialization
- Caption => The header title of that input field
- Datatype => The datatype represents the type of the value to return. Possible datatypes could be string, integer, float, datetime
- Cardinal => How many values need to get returned to the server? If it's 1 only one value needs to get returned, if it's n an uncertain amount of values get passed back to the server.
- Master => Are there any dependencies to other fields? If it's empty or "self" or "none" there are no dependencies. If there is a dependency, this input refers to other inputs. An example would be a dropdown component listening to a second dropdown component and changing its items to select when selecting an item in the other dropdown box.
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!




documentDataresulting a complicated object structure.