dynamic forms in react
JavaScript
class App extends React.Component {
constructor(props) {
super(props);
this.state = { values: [] };
this.handleSubmit = this.handleSubmit.bind(this);
}
createUI(){
return this.state.values.map((el, i) =>
<div key={i}>
<input type="text" value={el||''} onChange={this.handleChange.bind(this, i)} />
<input type='button' value='remove' onClick={this.removeClick.bind(this, i)}/>
</div>
)
}
handleChange(i, event) {
let values = [...this.state.values];
values[i] = event.target.value;
this.setState({ values });
}
addClick(){
this.setState(prevState => ({ values: [...prevState.values, '']}))
}
removeClick(i){
let values = [...this.state.values];
values.splice(i,1);
this.setState({ values });
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.values.join(', '));
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
{this.createUI()}
<input type='button' value='add more' onClick={this.addClick.bind(this)}/>
<input type="submit" value="Submit" />
</form>
);
}
}
ReactDOM.render(<App />, document.getElementById('container'));
Also in JavaScript:
- Title
- convert number to k m b javascript
- Category
- JavaScript
- Title
- createnodefield
- Category
- JavaScript
- Title
- how to print every array number combination possible
- Category
- JavaScript
- Title
- how to send enter event to input field jquery
- Category
- JavaScript
- Title
- color js
- Category
- JavaScript
- Title
- how to convert json to bootstrap treeview format
- Category
- JavaScript
- Title
- how to handle two url in one route in react
- Category
- JavaScript
- Title
- devexpress dxdatagrid custom text field
- Category
- JavaScript
- Title
- default pool size in sequelize
- Category
- JavaScript
- Title
- how to get data in json format in javascript
- Category
- JavaScript
- Title
- ckeditor change value
- Category
- JavaScript
- Title
- angularjs filter array of objects based on name prop
- Category
- JavaScript
- Title
- discord.js how to go back a file
- Category
- JavaScript
- Title
- array of objects javascript
- Category
- JavaScript
- Title
- discord.js send message to channel
- Category
- JavaScript
- Title
- Javascript compare two arrays
- Category
- JavaScript
- Title
- devextreme custom field
- Category
- JavaScript
- Title
- javascript .split().reverse.join
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- banking program deposit and withdrawal using ajax call
- Category
- JavaScript
- Title
- how to calculate average of array in javascript
- Category
- JavaScript
- Title
- callback function js
- Category
- JavaScript
- Title
- Javascript check for hash in URL
- Category
- JavaScript
- Title
- 'react-scripts' n’est pas reconnu en tant que commande interne ou externe, un programme exécutable ou un fichier de commandes.
- Category
- JavaScript
- Title
- find last element in array javascript
- Category
- JavaScript
- Title
- client side redirect javascript
- Category
- JavaScript
- Title
- google cdn jquery
- Category
- JavaScript
- Title
- bootstrap modal remove gray background
- Category
- JavaScript
- Title
- get id of clicked element javascript
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- get today's date javascript
- Category
- JavaScript
- Title
- include jquerty
- Category
- JavaScript
- Title
- chart js title
- Category
- JavaScript
- Title
- get only last 2 digit of year in javascript
- Category
- JavaScript
- Title
- delete with unlinksync node
- Category
- JavaScript
- Title
- bookshelf insert multiple rows
- Category
- JavaScript
- Title
- Attempted import error: 'uuid' does not contain a default export (imported as 'uuid').
- Category
- JavaScript
- Title
- deparam javascript
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- how to write in js
- Category
- JavaScript
- Title
- how to see node taints
- Category
- JavaScript
- Title
- express middleware pass parameter
- Category
- JavaScript
- Title
- equal to or more than javascript
- Category
- JavaScript
- Title
- how to transpose json data
- Category
- JavaScript
- Title
- angular $http abort request
- Category
- JavaScript
- Title
- date picker type react
- Category
- JavaScript
- Title
- filereader javascript example
- Category
- JavaScript
- Title
- Can't bind to 'formGroup' since it isn't a known property of 'form'
- Category
- JavaScript
- Title
- copy object javascript
- Category
- JavaScript
- Title
- discord.js reply to message
- Category
- JavaScript
- Title
- How to check whether a string contains a substring in JavaScript?
- Category
- JavaScript
- Title
- how to instialise var in js
- Category
- JavaScript
- Title
- copy one array to another javascript
- Category
- JavaScript
- Title
- add "hr" from javascript
- Category
- JavaScript
- Title
- How to create a function in javascript
- Category
- JavaScript
- Title
- blur javascript
- Category
- JavaScript
- Title
- how to check string uppercase or lowersace using regex javascript
- Category
- JavaScript
- Title
- how to compare two strings in javascript if condition
- Category
- JavaScript
- Title
- compare two arrays
- Category
- JavaScript
- Title
- draw rectangle on javascript canvas
- Category
- JavaScript
- Title
- javascript class click event
- Category
- JavaScript
- Title
- int to string javascript
- Category
- JavaScript
- Title
- angular trigger input change
- Category
- JavaScript
- Title
- discord.js bot github
- Category
- JavaScript
- Title
- how to create request body javascript
- Category
- JavaScript
- Title
- click on a radio button using jquery
- Category
- JavaScript
- Title
- angularjs iframe src binding
- Category
- JavaScript
- Title
- how to import npm packages in node.js?
- Category
- JavaScript
- Title
- javascript and
- Category
- JavaScript
- Title
- how to get nth fibonacci javascript
- Category
- JavaScript
- Title
- check first two number jquery
- Category
- JavaScript
- Title
- how to add an array to another array in javascript
- Category
- JavaScript
- Title
- javascript check if value in array
- Category
- JavaScript
- Title
- how to get href value of anchor tag in jquery in list
- Category
- JavaScript
- Title
- Inserting HTML elements with JavaScript
- Category
- JavaScript
- Title
- how to find unique elements in array in javascript
- Category
- JavaScript
- Title
- how to replace array element in javascript without mutation
- Category
- JavaScript
- Title
- adonisjs livereload
- Category
- JavaScript
- Title
- async await catch error
- Category
- JavaScript
- Title
- filter array react
- Category
- JavaScript
- Title
- array shift javascript
- Category
- JavaScript
- Title
- check items in array javascript
- Category
- JavaScript
- Title
- how to check if local storage variable exists in javascript
- Category
- JavaScript
- Title
- get url javascript
- Category
- JavaScript
- Title
- how to add javascript in html
- Category
- JavaScript
- Title
- check if class is active jquery
- Category
- JavaScript
- Title
- initialize a map js
- Category
- JavaScript
- Title
- anime.js morph svg d value
- Category
- JavaScript
- Title
- javascript check empty property
- Category
- JavaScript
- Title
- how to change tag name in js html
- Category
- JavaScript
- Title
- append array js
- Category
- JavaScript
- Title
- how to draw a flower in javascript
- Category
- JavaScript
- Title
- angular size of array
- Category
- JavaScript
- Title
- create react native app npx
- Category
- JavaScript
- Title
- check if checkbox is checked jquery
- Category
- JavaScript
- Title
- angular delete from array by name
- Category
- JavaScript
- Title
- empty textarea using jquery
- Category
- JavaScript
- Title
- dynamic for loop react
- Category
- JavaScript
- Title
- get results from db and put in javascript array codeigniter
- Category
- JavaScript
- Title
- how to display an image on text click using jQuery
- Category
- JavaScript