Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to refresh form inputs on model update? #6

Open
matias-sandell opened this issue Feb 25, 2016 · 10 comments
Open

Method to refresh form inputs on model update? #6

matias-sandell opened this issue Feb 25, 2016 · 10 comments

Comments

@matias-sandell
Copy link

Is there a method for refreshing form values or re-rendering the SchemaForm when the model updates? It seems the SchemaForm doesn't react (no pun intended) to model changes (for example when routing to another item, which in turn updates the model).

Not sure if it's an issue with material-ui or react-schema-form though.

Excellent work, by the way!

@stevehu
Copy link
Contributor

stevehu commented Feb 25, 2016

Frankly, I never thought about your use case before. And all the built in fields are optimised for performance. The worst case would to build a customized field that supports two way binding given that you only have one or two fields that need to be updated from outside.

@matias-sandell
Copy link
Author

OK, I probably need to add a refresh method to ComposedComponent since there could be a lot of fields depending on the editor type. Will get back to you with a PR when I have a solution.

@agrishun
Copy link
Contributor

Actually I'm struggling with the same issue, I think it can be a really popular use case. In order to achieve that, In ComposedComponent you can add componentWillReceiveProps and set the state, based on new model. Also props have to be changed from defaultValue to value, in some components like Text or Number. I think it would be a great feature to have, and I can submit a pull request at any moment. @stevehu what do you think about that?

@stevehu
Copy link
Contributor

stevehu commented May 20, 2016

Sounds good to me. We just need to make sure that array and fieldset work with refresh. Thanks

@Haggus
Copy link

Haggus commented Aug 18, 2016

I've also ran into a situation where I need my form to update, because of a model change. What is the status of this feature?

@foxdb
Copy link
Contributor

foxdb commented Aug 17, 2017

Hello!
I ran into this one too: my form model needs to be updated from outside to allow a "reset button" feature (on click on the button reset select fields to a specific value).

I worked out a solution by altering the Select component's state when it receives props. Let me know if that solution would suit you, and I'll have a PR ready!

Eventually, other components could be updated that way too.

@3thanHead
Copy link

@foxdb We are looking for a solution to this problem. Is anybody working on it?

@stevehu
Copy link
Contributor

stevehu commented Aug 18, 2017

@foxdb I think your solution should work if it applies to all types of field. I am looking forward to the PR. Thanks.

@stevehu
Copy link
Contributor

stevehu commented Aug 21, 2017

@foxdb Thanks for your help. We have several PRs recently and one of the PR got a small issue. I am still waiting for the developer to take a look and get it fixed. I don't know if we should have a release with a small issue. If someone is waiting for this feature, I will release it immediately with a comment.

#58

@b3j0f
Copy link

b3j0f commented Sep 11, 2017

In waiting, you can use a specific schemaform property for forcing rerendering.

For example, use a reset key which changes of value and is associated to the schemaform.

...
handleReset = () => this.setState({ reset: ! this.state.reset, model: this.props.model /* default model */ });
...
// rendering method
const { reset, model } = this.state;
return (
<SchemaForm key={this.state.reset} model={this.state.model} />
);
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants