Tell us which versions you are using:
Expect that I can dynamically change whether a field is hidden.
Changing the hidden property of the field options does not change the field visibility.
<Form
ref={c => this._form = c}
templates={templates}
type={this.state.struct}
options={this.state.options}
value={this.state.data}
onChange={this._handleChange}
/>
options.fields.myField.hidden = true
this.setState({ options })
nextProps.options !== this.props.options returns false and won't force an update.Researching a little further, it looks like a state change is invoking shouldComponentUpdate. The options prop updating is not. That would explain why nextProps.options === this.props.options. I'm only seeing it because a state change (at the same time the options are being updated to set the hidden property, during the screen load) is causing shouldComponentUpdate.
Because options={this.state.options} is changed on Form, which does not extend the local Component, shouldComponentUpdate is not invoked when this.state.options is updated. That explains the behavior. And from the way that Form uses Struct to create the form components, it does not appear there is a way to hide fields dynamically. Unless I'm missing something.
There's something new about this issue? I'm really having problems to use dynamic forms and keep default values.
Anyone can answer this ?
I'm also facing the same issue. Please help if anyone can?
Hi guys, i find an workaround hope this helps.
_handleFormChanges = values => {
let opts
if(values.interno){
opts = t.update(this.state.options, {
fields: {
legajo: {
hidden: {'$set': false}
}
}
})
}else{
opts = t.update(this.state.options, {
fields: {
legajo: {
hidden: {'$set': true}
}
}
})
}
this.setState({options: opts, value: values})
}
@ivanlynch solution doesn't work for me.
Has anybody found a solution? @tresheffron or @usmanuj7 or anybody else?
I also tried the supposed-to-be straightforward solution:
let newOptions = { ...this.state.options };
newOptions.fields.name.hidden = false;
this.setState({ options: newOptions });
Which didn't work either.
In both cases, I see that the hidden field is updated properly, and render is executed with the correct value. Still, it doesn't have an effect.
The initial setting of hidden does work.