3 Replies Latest reply on Mar 30, 2009 10:37 AM by lrp

    Focus after reRender

    lrp

      Hey there,

      I have an HtmlSimpleTogglePanel with different fields, among them an HtmlInputText. On this field I have ajax support set to call an action that updates the toggle panel's label with the value of the text field. This works great, but whenever I type in the text field and the page rerenders the toggle panel the text field loses focus (I suspect this is because it is located inside another component that is being rerendered). I tried using the setFocus() method on the ajax support with the id of the text field. This works too, but the entire contents of the text field is marked whenever it gets focus set, meaning that continuous writing is impossible (seeing as how writing while text is marked means the marked text disappears).

      Is there any way to make sure the HtmlInputText does not lose focus after its parent component is rerendered, or alternately some way to regain focus to it without marking all the text?

        • 1. Re: Focus after reRender
          lrp

          I managed to find an ok workaround. I update the label and data model every onkeyup event, but I only rerender the toggle panel on the onblur event.

          I guess a better workaround would be to make the onfocus event of the text field set the input marker at the end of the already existing text. I'll look into whether that is possible or not.

          • 2. Re: Focus after reRender
            ilya_shaikovsky

            update just outputText in header but not the whole panel.

            • 3. Re: Focus after reRender
              lrp

              That worked great. Thanks a lot!