最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Wicket 1.5 Autocomplete Textfield onUpdate Behavior not called - Stack Overflow

matteradmin2PV0评论

My AutoCompleteTextField (getChoices method implemented and working):

AutoCompleteTextField<String> objectDescription = new AutoCompleteTextField<String>("objectDescription") { 
     getChoices() {...}
}

To this textfield I add:

objectDescription.add(new OnChangeAjaxBehavior()) {
     onUpdate() {....}
}

The onUpdate method gets called everytime I write something in my textfield but not when I choose some item from the autoplete menu. The string from the menu is written to the textfield but only calls the onUpdate when another change is made.

Edit: Before Wicket 1.5 this was working.

My AutoCompleteTextField (getChoices method implemented and working):

AutoCompleteTextField<String> objectDescription = new AutoCompleteTextField<String>("objectDescription") { 
     getChoices() {...}
}

To this textfield I add:

objectDescription.add(new OnChangeAjaxBehavior()) {
     onUpdate() {....}
}

The onUpdate method gets called everytime I write something in my textfield but not when I choose some item from the autoplete menu. The string from the menu is written to the textfield but only calls the onUpdate when another change is made.

Edit: Before Wicket 1.5 this was working.

Share Improve this question edited Nov 8, 2011 at 8:45 rotsch asked Nov 8, 2011 at 8:37 rotschrotsch 1,94916 silver badges36 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Add an AjaxFormComponentUpdatingBehavior("onchange").

The OnChangeAjaxbehavior() seems to fire at every change (uses the Javascript Wicket.ChangeHandler), like in every key press.

Using an AjaxFormComponentUpdatingBehavior will add the event listener to onChange javascript events, like in focusing out of the textfield with a different value, or in selecting a value from the autoplete list.

Still not sure why doesn't OnChangeAjaxbehavior extends AjaxFormComponentUpdatingBehavior inherit this logic from AjaxFormComponentUpdatingBehavior, there must be something it's overriding.

UPDATE This might well be the reason why onchange javascript events are being ignored when using OnChangeAjaxBehavior. The source code for Wicket.ChangeHandler, found in wicket-ajax.js, sets handlers for different events:

  • Backs up the onchange event handler in onchangeoriginal:
obj.onchangeoriginal = obj.onchange
  • If the browser is IE, Safari, and some other, it assigns the original onchange event handler to onKeyUp, onpaste and oncut.
  • If not, it assigns the original onchange event handler to onInput.
  • Finally, it always removes the onchange event handler:

    obj.onchange = function(event){
        Wicket.stopEvent(event);
    }

The code in wicket-autoplete.js seems to be manually firing the onchange event handler at item selection. Probably it should be checking for obj.onchangeoriginal first.

So, being this js executed in OnDomReady, I doubt it's possible to make those two behaviors coexist. Maybe it's time to file a new JIRA?

This might be a slightly related issue: WICKET-2424: OnChangeAjaxBehavior + DatePicker do not work together

Post a comment

comment list (0)

  1. No comments so far