Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Can I set the focus on a form?

    I have a DynamicForm that I want to be readonly by default. When the user clicks a "edit" button, form.setCanEdit(true) is called. I want to give it focus as well (preferably on the first focusable item). I can't get this to work.

    Is this possible and if so, how?

    #2
    Any help would be appreciated...

    Comment


      #3
      You didn't say what you actually tried - but you should read the doc for DynamicForm.focusInItem() and autoFocus.

      Comment


        #4
        I've been struggling with focusInItem and autoFocus for hours, if not days. :-(

        Each form initially is "read-only". Then when the user clicks an "edit" button, I call DynamicForm#setCanEdit(true). It should then set the focus in the first editable field. Since my application is more or less generically set-up I do not known the name of the first editable item. I could of course look it up and try to set it.

        Comment


          #5
          As feedback (maybe helpful to others), I've not managed to get it working the way I wanted it. Probably because the form isn't drawn (completely) when I set the focus, so I ended up using a 100ms timeout and then it works. This is what I have achieved:

          1) Show form and "edit" button
          2) Disable editing mode via form.setCanEdit(false)
          3) If user clicks "edit' button, enable editing mode via form.setCanEdit(true)
          4) Set focus in first editable and focusable item (I created my own function for this) via window.setTimeout(form.setFocusInFirstItem(), 100)

          (Ideally, the timeout isn't necessary)

          Comment

          Working...
          X