-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
There is a bug with the ListField when I remove one ObjectField and then display an other item in the Form.
To get the issue, please follow these instructions :
- Click on "Item 1"
- Click on "Item 2" -> Until here, Everything works fine.
- Remove an sub-item from "Item 2"
- Click on "Item 1" -> CRASH
Error : Uncaught TypeError: Cannot read property 'value' of undefined
App File :
import React, {Component} from 'react';
import ItemForm from '../item/item-form';
const items = [
{
id: 1,
name: 'Item 1',
code: '1234',
subitems: [{id: '11', name: 'Item 1.1'}, {id: '12', name: 'Item 1.2'}]
},
{
id: 2,
name: 'Item 2',
code: '5678',
subitems: [{id: '21', name: 'Item 2.1'}, {id: '22', name: 'Item 2.2'}]
}
];
class TestForm extends Component {
constructor(props) {
super(props);
this.state = {selectedItem: 0};
this.onItemChange = this.onItemChange.bind(this);
}
onItemChange(e) {
this.setState({selectedItem: e.target.id});
}
render() {
const item = items[this.state.selectedItem];
return (
<div>
<p id={0} onClick={this.onItemChange}>
Item 1
</p>
<p id={1} onClick={this.onItemChange}>
Item 2
</p>
<br />
<br />
<ItemForm item={item} />
</div>
);
}
}
export default TestForm;
ItemForm file :
import React, {Component} from 'react';
import {
Form,
TextField,
NumberField,
ObjectField,
ListField,
FormEventsEmitter
} from 'react-components-form';
class ItemForm extends Component {
constructor(props) {
super(props);
this.state = {item: null};
this.eventsEmitter = new FormEventsEmitter();
}
/** Update the state with Props */
static getDerivedStateFromProps(nextProps) {
return nextProps;
}
render() {
this.eventsEmitter.emit('reset', this.state.item);
return (
<Form
eventsEmitter={this.eventsEmitter}
model={this.state.item}>
<TextField type="text" label="Name" name="name" />
<NumberField type="number" label="Code" name="code" />
<ListField label="Subitems" name="subitems">
<ObjectField>
<NumberField type="number" label="Id" name="id" />
<TextField type="text" label="Name" name="name" />
</ObjectField>
</ListField>
</Form>
);
}
}
export default ItemForm;
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels