5 Replies Latest reply on Nov 18, 2016 5:41 AM by sdejager RSS
    sdejager Explorer

    Force focus to a textbox

    Is there a way to force focus to a certain textbox?
    For example: if a reset button is pushed, the focused must be set to the cleared textbox and not remain on the button.

     

    Kind regards,
    Simon de Jager

      • Re: Force focus to a textbox
        ttielebein Collaborator

        I do not see any way of doing this. If the tab sequence on the textbox is set to 1, and the page is refreshed, then it refocuses the textbox first. I tried using some kind of session variable button click combination where the value for the textbox is stored and reloaded into the textbox automatically, and the whole mashup refreshed upon button click, but this didn't work.

        • Re: Force focus to a textbox
          ttielebein Collaborator

          Ok, I got it! You can force refresh the page, and this will force auto-select the textbox so long as it is set to tab sequence 1. Here is what you need to do:

           

          1. Create a session variable (see KCS Article CS249180 for a basic session variable example)

          2. Because you are binding the value from this textbox to a session variable, back to the same textbox, you need to use a setter method and getter method. Otherwise, the textbox session variable will just be overwritten when the page is refreshed

          3. Create a setter method with string input "input_str" and the following Javascript: Resources["CurrentSessionInfo"].SetGlobalSessionStringValue({name: "your_session_var", value: input_str});

          4. Import this setter method and the GetGlobalSessionValues service from the CurrentSessionInfo resource in the Data tab on a mashup:

          5. Add a textbox, button, and validator widget to the mashup

          6. Bind the "Text" target from the textbox to the set service

          7. Bind the session variable under All Data in GetGlobalSessionValues to the textbox "Text" target

          8. Bind the Click event from the button to the setter service created in step 3

          9. Bind the ServiceInvokeCompleted event from the setter service created in step 3 to the validator widget's "Evaluate" target

          10. Set the expression of the validator widget to "location.reload()"

          11. View the mashup, enter a value into the box, and hit the button; the page should reload and the box should now be selected with the same text as previously entered

           

          Let me know your further questions on this

            • Re: Force focus to a textbox
              sdejager Explorer

              Thank you for the info, but this is not what I meant.
              What my goal is, is to use a button to call the "ResetToDefault" of a textbox, and move the focus to that textbox.
              What currently happens is I click the button, the value gets cleared, but the focus remains on the button, not the textbox.

            • Re: Force focus to a textbox
              carlesc Ninja

              Hi Simon, this is the way ( low level tweaks )

              Knowing that there's jQuery behind the scenes and looking on HTML generated by a textbox:

               

              Add and Expression Widget, and set it with $("#root_Textbox-4-bounding-box").find("input").focus() and you just need to trigger it, where Textbox-4 it's the TextBox Id that you will find as the first property on the TextBox  on the Mashup.