-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Editing input fields #39
Comments
Common "problem" with React: You'll find lots of github issues at Reagent/OM and others with the exact same problem. The only fix is to use .setState(). Though, I'd probably recommend using uncontrolled inputs: https://facebook.github.io/react/docs/forms.html Changing it do |
Thanks for that @hura, that will solve my immediate problem. Could I recommend that the simple example be changed to the same uncontrolled input behaviour, and perhaps a future example deal with a more complex controlled input example? |
Yes, I think the example should be fixed. You could do a pull request. IMHO a more complex example should go to reagent since it's not really re-frame specific. I'd say the reagent wiki would be a good place if you find out a nice way to do this. |
If anyone is writing this up, in addition to @hura's links here is more background: |
@whodidthis made this observation via the news group:
We tend to use |
Yeah, I'm sort of forming the opinion that re-frame isn't a really good fit for the char by char view updates, but I hope char by char app-db updates will work. I'm going to try and work on some simple ideas for the simple example and hopefully figure something good out that fits into the re-frame conceptual model, then do some work on a pull request for the example and wiki. |
Shaun, have you seen the related conversation (and proposed workaround) in On 5 April 2015 at 03:29, Shaun Mahood notifications@github.com wrote:
|
I would love to see some examples on the wiki on how we deal with input. I've been getting very frustrated (lots of it to do with my own lack of understanding :)). I initially tried to use
|
So I was able to get a form-3 component with char by char updates mostly working. It mostly fixes the problem of resetting the cursor position, but there is still the issue of lag and missing keystrokes when typing quickly. I've put up a repo with some different methods of controlled inputs at https://github.com/smahood/re-frame-inputs It's a bit ugly, but the examples with the form-3 components seem like they have some promise for true char by char updates. If anyone wants to look at it, my next thought is to offload some of the synchronization between the components and app-db into the component local state so that the input lag is moved from the ui display to the speed of updating the app-db. Not sure how yet though. My thought is to use the repo to experiment and then use the results to write up some patterns in the wiki. Feel free to poke around in there and suggest improvements or point out mistakes. |
|
Well, that is way easier. Is there anywhere that it will cause problems? I was reading https://groups.google.com/forum/#!topic/clojurescript/_XvbwEVYVUc and just assumed it was more trouble than it was worth, but maybe this is just the situation it is meant for. @mike-thompson-day8 if you can confirm that calling dispatch-sync in the on-change handler for text inputs is a safe default, then I will update the simple-example and do a pr for it as well as write up the first draft of a wiki page for handling inputs. |
Actually i was the one being a bad and spreading some doubts about dispatch-sync. But that was just me being a bad, dispatch-sync is perfect. React puts in a lot of work to make focus work while updating form elements, synchronous changes are the only way it works. |
I was wondering how to complete this ticket:
|
I would update the simple example, add an FAQ and even update the front On 21 April 2015 at 14:00, mike-thompson-day8 notifications@github.com
|
Happy to do this after next week? On 21 April 2015 at 14:03, Colin Yates colin.yates@gmail.com wrote:
|
Replace dispatch with dispatch-sync for issue #39
The new router loop solves this problem. Because it no longer uses core.async, the delays are gone. See 420e42a |
Decided that instead of binding a component against an atom, I'd just send a notification on change. That way I can keep all state in one place and clear it if necessary, something that becomes ugly when the state for the textarea is kept on an atom. Mike Thompson suggested doing it on-blur instead of updating every on-change (because of day8/re-frame#39). While dispatching on-blur is cleaner, I can't update the textarea to change or clean it unless I use the `value` attribute... which is blank until we exit it. Looks like I have to use `on-change`, so the event needs to be fired with dispatch-sync.
re-frame seems to have trouble with controlled vs uncontrolled input elements. Looks like using :default-value helps though: day8/re-frame#39 (comment)
When running the simple example, if the color textbox is edited anywhere before the end of the input, when the input is changed it will reset the cursor to the end of the input box.
Any idea how to fix this? I used it as an example for how to save form input and am running into the same problem in my own app as well.
The text was updated successfully, but these errors were encountered: