I'm trying to get a working remove button for my different categories of things but my remove button only adds just like my add button.
I supposed that's to be expected when using "concat" but I don't know how I'm supposed to be doing this.
I got help for adding here : Add Inputs in React with add button
But how do I delete the last element (perhaps cheking that user has not filled it in beforehand)?
/* ************************************* */
/* ******** IMPORTS ******** */
/* ************************************* */
import React, { Component } from 'react';
import { Card, CardBlock, Button, InputGroup, Input } from 'reactstrap';
import ProviderInfos from '../ProviderInfos/ProviderInfos';
/* ************************************* */
/* ******** VARIABLES ******** */
/* ************************************* */
/* ************************************* */
/* ******** COMPONENT ******** */
/* ************************************* */
export default class SearchExtendedComponent extends Component {
constructor(props) {
super(props);
this.state = { inputCurry: [],
inputWurst: [],
inputSausage: [],
inputPretzel: [],
Curry: 1,
Wurst: 1,
Sausage: 1,
Pretzel: 1 };
this.incrementCurry = this.incrementCurry.bind(this);
this.decrementCurry = this.decrementCurry.bind(this);
this.incrementWurst = this.incrementWurst.bind(this);
this.decrementWurst = this.decrementWurst.bind(this);
this.incrementSausage = this.incrementSausage.bind(this);
this.decrementSausage = this.decrementSausage.bind(this);
this.incrementPretzel = this.incrementPretzel.bind(this);
this.decrementPretzel = this.decrementPretzel.bind(this);
}
componentDidMount() {
this.incrementCurry();
this.incrementWurst();
this.incrementSausage();
this.incrementPretzel();
}
incrementCurry() {
const inputCurry = this.state.inputCurry;
this.setState({
Curry: this.state.Curry + 1,
inputCurry: inputCurry.concat(<InputGroup>
<Input placeholder="Curry" key={this.state.Curry} /><ProviderInfos /></InputGroup>),
});
}
decrementCurry() {
const inputCurry = this.state.inputCurry;
this.setState({
Curry: this.state.Curry - 1,
inputCurry: inputCurry.concat(<InputGroup>
<Input placeholder="Curry" key={this.state.Curry} /><ProviderInfos /></InputGroup>),
});
}
incrementWurst() {
const inputWurst = this.state.inputWurst;
this.setState({
Wurst: this.state.Wurst + 1,
inputWurst: inputWurst.concat(<InputGroup>
<Input placeholder="Wurst" key={this.state.Wurst} /><ProviderInfos /></InputGroup>),
});
}
decrementWurst() {
const inputWurst = this.state.inputWurst;
this.setState({
Wurst: this.state.Wurst - 1,
inputWurst: inputWurst.concat(<InputGroup>
<Input placeholder="Wurst" key={this.state.Wurst} /><ProviderInfos /></InputGroup>),
});
}
incrementSausage() {
const inputSausage = this.state.inputSausage;
this.setState({
Sausage: this.state.Sausage + 1,
inputSausage: inputSausage.concat(<InputGroup>
<Input placeholder="Sausage" key={this.state.Sausage} /><ProviderInfos /></InputGroup>),
});
}
decrementSausage() {
const inputSausage = this.state.inputSausage;
this.setState({
Sausage: this.state.Sausage - 1,
inputSausage: inputSausage.concat(<InputGroup>
<Input placeholder="Sausage" key={this.state.Sausage} /><ProviderInfos /></InputGroup>),
});
}
incrementPretzel() {
const inputPretzel = this.state.inputPretzel;
this.setState({
Pretzel: this.state.Pretzel + 1,
inputPretzel: inputPretzel.concat(<InputGroup>
<Input placeholder="Pretzel" key={this.state.Pretzel} /><ProviderInfos /></InputGroup>),
});
}
decrementPretzel() {
const inputPretzel = this.state.inputPretzel;
this.setState({
inputPretzel: inputPretzel.deleteElement(this.state.Pretzel),
Pretzel: this.state.Pretzel - 1,
});
}
render() {
return (
<Card>
<CardBlock className="main-table">
<fieldset>
<legend>Currys</legend>
{this.state.inputCurry}
<button onClick={this.incrementCurry}>Ajouter un Curry</button>
<button onClick={this.decrementCurry}>Enlever un Curry</button>
</fieldset>
<fieldset>
<legend>Wursts</legend>
{this.state.inputWurst}
<button onClick={this.incrementWurst}>Ajouter un Wurst</button>
<button onClick={this.decrementWurst}>Enlever un Wurst</button>
</fieldset>
<fieldset>
<legend>MasterSausages</legend>
{this.state.inputSausage}
<button onClick={this.incrementSausage}>Ajouter un Sausage</button>
<button onClick={this.decrementSausage}>Enlever un Sausage</button>
</fieldset>
<fieldset>
<legend>Pretzels</legend>
{this.state.inputPretzel}
<button onClick={this.incrementPretzel}>Ajouter un Pretzel</button>
<button onClick={this.decrementPretzel}>Enlever un Pretzel</button>
</fieldset>
<Button color="secondary">Options</Button>{' '}
<Button id="btn">Exécuter</Button>
</CardBlock>
</Card>
);
}
}
As you can see I tried something new on the fourth element (pretzels) but "deleteElement" is not an accepted function for this object type and I got :
Uncaught TypeError: inputMultiProvider.deleteElement is not a function
In the console.