Reactjs – Attributes that cannot get materials – UI SELECTFIELD IN React

I am using SelectField material-ui as my react item.
I tried Can’t get the target attributes of material-ui select react component from this answer.
Many methods.

But they don’t work. My target.id is always equal to “”
How can I get attributes (like id).

This Is my code:

constructor(props) {
super(props);
this.state = {
form: {< br /> resident_city:''

},
ret_code:'',
ret_msg:''
};
this.handleList = this. handleList.bind(this);
}

handleList(event, index, value) {
event.persist()
const field = event.target.id ;
const form = this.state.form;
form[field] = value;
console.log(event, value)
this.setState({
form
});
console.log(form);
}



style ={style}
id="city"
value={this.state.form.re sident_city}
onChange={this.handleList}
maxHeight={200}
>
{cities}

Update

I tried to use SelectField without a form, and I still can’t get the id attribute. This really confuses me.

On the main component, you define a prop name for the selection form component, assuming your city component is called: cityForm

In your cityForm component

render() {
return (
style={style}
value={this.props.city}
onChange={(e, index, value) => this.props.selectChange(e, index, value, this.props.cityName)}
maxHeight= {200}
>
{cities}

);
}
}

In your main In the function, you will say (the code is cut and some parts are omitted)

handleSelectChange(e, index, value, name){
this.setState({
[name]: value,
});
}

rend er(){
return (

);
}
}

I am building a dynamic form generator and it does the trick for me =).

I am using SelectField material -ui as my react project.
I tried many methods from this answer Can’t get the target attributes of material-ui select react component
.

But they don’t It works. My target.id is always equal to “”
How can I get attributes (such as id).

This is my code:

constructor(props) {
super(props);
this.state = {
form: {
resident_city:''

} ,
ret_code:'',
ret_msg:''
};
this.handleList = this.handleList.bind(this);
)

handleList(event, index, value) {
event.persist()
const field = event.target.id;
const form = this.state.form;
form[field] = value;
console.log(event, value)
this.setState({
form
});
console.log( form);
}


style={style}
id="city"
value={this.state.form.resident_city}< br /> onChange={this.handleList}
maxHeight={200}
>
{cities}

Update

I tried to use SelectField without a form, and I still can’t get the id attribute. This really confuses me.

< p>On the main component, you define a prop name for the selection form component, assuming your city component is called: cityForm

In your cityForm component

< /p>

render() {
return (
style={style}
value={this.props.city}
onChange= {(e, index, value) => this.props.selectChange(e, index, value, this.props.cityName)}
maxHeight={200}
>
{cities}

);
}
}

In your main function, you would say (the code is cut and some parts are omitted)

handleSelectChange(e, inde x, value, name){
this.setState({
[name]: value,
});
}

render(){
return (

);
}
}

I am building a dynamic form generator and it did the trick for me =).

Leave a Comment

Your email address will not be published.