I have following JSON string from which I need to dynamically create DOM of the form:
{
"formData": [{
"inputType": "text",
"type": "string",
"min": 10,
"label": "Enter Name:",
"objectId": "test1"
}],
"gridLayout": {
"rows": [
{
"column": [
{
"width": "4",
"id": "test1"
}
]
}
]
}
}
from the gridLayout object, I wish to create bootstrap style grid. For instance, first rowobject of the JSON's "rows" has 1 column in the columns object with width of 4. Thus, the layout for that row should be
<div class="row">
<div class="col-md-4" id="test1">
</div>
</div>
Later, using formData object of JSON, TextBox component should be appended to grid layout like so:
<div class="row">
<div class="col-md-4" id="test1">
<TextBox />
</div>
</div>
For now, I have written code to display the TextBox component as it is without the grid layout in following way.
Form.jsx:
class Form extends React.Component {
getComponent = (formObj, index) => {
let returnString;
if (formObj.inputType === 'text') {
returnString = (<TextBox key={index} />);
}
return returnString;
}
render() {
let formData = JSON.parse(this.getData()).formData;
return (
<React.Fragment> {formData.map((o, index) => this.getComponent(o, index))} </React.Fragment>
);
}
}
Thus now, how do I dynamically create the Grid Layout and insert the TextBox component in it?
TextBoxend up in a particular column? You have duplicateids, so it's difficult to find the correct column.TextBoxcomponents for tworowobjects. This one's shorter version of the json.