wicket-select2 icon indicating copy to clipboard operation
wicket-select2 copied to clipboard

Any way to be notified of selected choices?

Open vertex-github opened this issue 10 years ago • 6 comments

Igor - is there any way to be notified via a callback of a user selection in a Select2MultiChoice?

Ive got the component hooked up and working fine, complete with search function, but Im trying to sync the selected items in the MultiChoice after each user selection - is this possible?

vertex-github avatar Apr 03 '14 01:04 vertex-github

No problem, simply do something like this:

Select2MultiChoice<String> multiChoice = new Select2MultiChoice<String>(
  "multiChoice", model, choiceProvider);
form.add(multiChoice);

multiChoice.add(new AjaxEventBehavior("change")
{
  @Override
  protected void onEvent(AjaxRequestTarget target)
  {
    // do something useful here
  }
});

tgoetz avatar Apr 03 '14 06:04 tgoetz

Ah ok, if you'd like to sync on each change then you better do something like this:

multiChoice.add(new AjaxFormSubmitBehavior(form, "change")
{
  @Override
  protected void onSubmit(AjaxRequestTarget target)
  {
    // do something useful here
  }
});

tgoetz avatar Apr 03 '14 07:04 tgoetz

Thanks Tom! Will this submit the whole form or just the items in the MultiChoice?

vertex-github avatar Apr 03 '14 12:04 vertex-github

This will submit the whole form. If you just want to submit the values of the MultiChoice, try org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior.

tgoetz avatar Apr 03 '14 12:04 tgoetz

I already tried that using: emailsMC.add( new AjaxFormComponentUpdatingBehavior( "change" ){...}

The IModel isnt being updated as expected - hence this question :-)

vertex-github avatar Apr 03 '14 12:04 vertex-github

Just tried AjaxFormComponentUpdatingBehavior in a quickstart and it works fine for me ...

tgoetz avatar Apr 03 '14 12:04 tgoetz