Announcement

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

    want to move focus when enter key is pressed

    Hi,

    Some textItems, checkboxItems and a buttonItem are assigned to a DynamicForm.
    Because my user wants to press enter key only to move focus
    from a textItem to the next one, not by pressing tab key,
    I wrote a custom ItemKeyPressHandler to detect enter key pressed.

    When textItems or checkBoxItems have focus, ItemKeyPressEvent is fired as expected.
    But when buttonItem has focus, ItemKeyPressEvent is not fired.

    My alternative is to add a dirty line of code, dynamicForm.focusInItem( "firstTextItem" )
    at the end of the buttonItem's clickHandler. But I am surprised to find
    out this is not working either.

    Any workaround ?

    Regards,

    veritas

    #2
    Ooops !

    dynamicForm.focusInItem( "firstTextItem" ) inside ButtonItem's ClickHandler works fine.
    I'm sorry.

    veritas

    Comment


      #3
      How to focus in next item when user presses Enter key

      Code:
      	@Override
      	public void onItemKeyPress(ItemKeyPressEvent event) {
      		if(event.getKeyName().equals("Enter")){
      			event.getItem().getForm().focusInItem(nextItemNumber(event.getItem()));
      		}
      	}
      	
      	private Integer nextItemNumber(FormItem item){
      		FormItem[] fields = item.getForm().getFields();
      		for(int itemNumber=0;itemNumber<fields.length; itemNumber++){
      			if(item.equals(fields[itemNumber])&&itemNumber+1<fields.length){
      				return itemNumber+1;
      			}
      		}
      		return 0;
      	}

      Comment

      Working...
      X