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

Update form when atom is replaced? #107

Open
bpicolo opened this issue Jun 14, 2016 · 7 comments
Open

Update form when atom is replaced? #107

bpicolo opened this issue Jun 14, 2016 · 7 comments

Comments

@bpicolo
Copy link

bpicolo commented Jun 14, 2016

I believe I'm hitting similar behavior to a few of the other issues, but it's quite unclear how to resolve.

I have a form as so:

(defn some-form [foo] 
   (let [doc (r/atom {:bar (:bar foo)])
     (fn []
         [bind-fields some-form-template doc])))

The issue is, when some-form is re-rendered (because a level above it is reacting to @\foo), the form does not seem to re-render. (If I throw in a some text field reacting to @\doc here, the text field will update)

What is the proper way to handle this? It's not quite that I am updating the atom externally, it's that I'm asynchronously loading the data that goes into the atom. I want to replace it entirely.

@yogthos
Copy link
Member

yogthos commented Jun 14, 2016

In your example, you're creating the doc atom once the first time the form is rendered. That code will not be rerun on changes to foo. The only way to do this right now would be to pass foo directly to bind-fields. Unfortunately, not all the fields can handle external updates so YMMV with that approach.

@bpicolo
Copy link
Author

bpicolo commented Jun 14, 2016

@yogthos

The question is more this. I want to populate a form with some data I fetch asynchronously. How can I make sure that, given I start with no data and render an empty form, then load data to populate it, how to I make sure it's populated with that latter data?

@yogthos
Copy link
Member

yogthos commented Jun 14, 2016

Currently, the data has to be available at the time bind-fields runs. This is the same issue as #19 where the atom has to be updated externally after the form is created.

@khdegraaf
Copy link

Actually, it appears to work properly for textbox, and I have a fix for :list. It looks like radio groups and selection groups have this problem still. It looks like a minor fix to handle, I may give it a try for some other fields...

@yogthos
Copy link
Member

yogthos commented Sep 24, 2016

Yeah that looks promising, if you think you can get it to work I'd love a pr for this.

@khdegraaf
Copy link

Tested fix for single-select for selection groups. See mods at https://github.com/khdegraaf/reagent-forms. Multi-select may be fixed too, but haven't tested it. Did test and verify checkbox, textbox (and presumably variations), and datepicker all work in my project. I haven't tested the others. I'll do a push request at some point.

@yogthos
Copy link
Member

yogthos commented Sep 29, 2016

Fantastic, thanks for spearheading this.

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

3 participants