Skip to content

Commit

Permalink
Creating <Input /> Components Dynamically, based on the JS Config,
Browse files Browse the repository at this point in the history
inside the `<ContactData />` Component
  • Loading branch information
Ch-sriram committed Aug 17, 2020
1 parent 1d2697d commit dae73e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ Firebase Common API Endpoint: <https://burger-builder-ram.firebaseio.com/>

1. Creating a Custom Dynamic `<Input />` Component: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/3576b226a1f6c453948052e66b10a3da85da10cc)
2. Setting-up JS Config for the Form in `<ContactData />` Component: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/10c4e62025e610b6fb6259a0caa5311082a3f614)
3. Creating `<Input />` Components Dynamically, based on the JS Config, inside the `<ContactData />` Component: [Commit Details]()
38 changes: 15 additions & 23 deletions src/containers/Checkout/ContactData/ContactData.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,23 @@ class ContactData extends Component {
};

render() {
const formElementsArray = [];
for (let key in this.state.orderForm) {
formElementsArray.push({
id: key,
config: this.state.orderForm[key]
})
}
let form = (
<form>
<Input
elementType="input"
elementConfig="..."
value="..."
/>
<Input
input_type="input"
type="email"
name="email"
placeholder="Your E-Mail"
/>
<Input
input_type="input"
type="text"
name="street"
placeholder="Street Address"
/>
<Input
input_type="input"
type="text"
name="postal"
placeholder="Postal Code"
/>
{formElementsArray.map(formElement => (
<Input
key={formElement.id}
elementType={formElement.config.elementType}
elementConfig={formElement.config.elementConfig}
value={formElement.config.value}
/>
))}
<Button type="success" onClick={this.orderHandler}>
ORDER
</Button>
Expand Down

0 comments on commit dae73e0

Please sign in to comment.