I try to remove object in array, and my task is to send the list without id, becuse in array of list has id, i want to remove that id, so in list just answer and question : {}. why i put id because i follow intruction from other guy to create random id to make add list success. see code below in handleadd
initialState:
this.state = {
post : props.post,
post2 : props.post2,
list : [],
object : {
answer : '',
id : '',
question : {
question : ''
}
},
handleAdd and handleForm:
handleTextBox = ({target : { name, value, id }}) => {
const newList = this.state.list.map(obj => {
if (obj.id === id) return {...obj, [name] : value , question : { [name] : value }}
return obj
})
this.setState({
list : newList
})
}
handleAdd = e => {
this.setState({
list : [
...this.state.list,
{
...this.state.object,
id : shortid.generate(),
}
]
})
}
component:
if (questionId === "Create Own Question") {
return <Fragment>
{
this.state.list.map(h => (
<Fragment>
<Col span={24} className="form-password">
<AtiField name="question" >
<AtiTextbox
id ={h.id}
name="question"
type ="text"
placeholder="Question"
size="sm"
value = {h.question.question}
className={`pocketbank-form form-control ${this.state.formError.question ? 'is-invalid' : '' }`}
label={<FormattedMessage id="label.form.question" />}
events={{
onChange : this.handleTextBox
}}
/>
{formError.question}
</AtiField>
</Col>
<Col span={24} className="form-password">
<AtiField name="answer" >
<AtiTextbox
id = {h.id}
name = "answer"
type = "text"
placeholder = "Security Answer"
size = "sm"
value = {h.answer}
className = {`pocketbank-form form-control ${this.state.formError.securityAnswer ? 'is-invalid' : '' }`}
label={<FormattedMessage id="label.form.answer" />}
events={{
onChange : this.handleTextBox
}} />
</AtiField>
{formError.securityAnswer}
</Col>
</Fragment>
))
}
<Col span={24} className="form-password">
<AtiField name="paramKey" >
<AtiButton
text="+"
type="primary"
outline={true}
block={false}
events={{ onClick: (event) => this.handleAdd(event) }}
/>
</AtiField>
</Col>
</Fragment>
}
I expect i can remove an object especially id