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

b:inputText with ajax="true" loses focus after update #680

Closed
ggam opened this issue Apr 5, 2017 · 8 comments
Closed

b:inputText with ajax="true" loses focus after update #680

ggam opened this issue Apr 5, 2017 · 8 comments
Assignees
Milestone

Comments

@ggam
Copy link
Collaborator

ggam commented Apr 5, 2017

This is somewhat related to #678. When using <b:inputText value="#{...}" ajax="true" />, every key that is pressed results in an AJAX request, rerendering the whole form and losing input focus.

Two workarounds I see:

  • Set the update attribute to something that does not contain the input
  • Add an ajax oncomplete callback to regain focus.
@stephanrauh
Copy link
Collaborator

stephanrauh commented Apr 5, 2017 via email

@stephanrauh
Copy link
Collaborator

stephanrauh commented Apr 5, 2017

What's a sensible default event setting? onblur? onchange?

Tentatively, I'll set it to onblur because that solves the focus problem.

@stephanrauh
Copy link
Collaborator

I've uploaded a new developer snapshot to Maven Central. See #369 on how to get it. I'll close this issue, but keep listening to the comments. If the issue turned out not to be solved, don't hesitate to re-open it.

@ggam
Copy link
Collaborator Author

ggam commented Apr 6, 2017

I've tested it and it works, but I personally prefer the previous behaviour, as now I have to move the focus out of the field.

Would it be possible to just regain focus? Or is it too difficult for now?

@stephanrauh
Copy link
Collaborator

stephanrauh commented Apr 6, 2017

Yes, regaining the focus is almost impossible. Or rather, it's difficult to do it right. Mind you, it's easy to regain the focus. But then, you'd also regain the focus when the user hits the TAB key. And what happens if the user uses the cursor keys to navigate within the field? The field is replaced when the onkeyup event triggers. That, in turn, means that the cursor is not where the user wants it to be. And I didn't even talk about marking the content of the field :).

BTW, you can easily restore the old functionality by using the onkeyup property. I don't know what you do with the AJAX request now. Most likely there's a Java bean method you're calling? If so, just write onkeyup="ajax:myBean.myMethod()" to call the method after every keystroke.

@NicolaIsotta
Copy link
Contributor

The h:inputText default event in mojarra is change. I think It shouldn't have problems with focus too.

@stephanrauh
Copy link
Collaborator

BTW, I'll align the default event with standard JSF. There, it's "onchange", as you've suggested in #679.

@stephanrauh
Copy link
Collaborator

@NicolaIsotta Thanks for confirming that. The default event of the JSF class HtmlInputText is valueChange. That confused me, but you're right, it's obviously no valid HTML. I've set the default event of b:inputText, b:inputTextarea and b:selectOneMenu to change (which is translated to onchange in JavaScript).

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