wicket-jquery-ui icon indicating copy to clipboard operation
wicket-jquery-ui copied to clipboard

InputDialog - submit using enter key

Open tszpinda opened this issue 11 years ago • 5 comments

Would be great if submit using entry could work with the InputDialog, any idea where to look to get this fixed?

tszpinda avatar Jan 15 '14 15:01 tszpinda

Hi,

I think this can be handled (and activated trough a #isEnterEventEnabled or something similar) I will look at this...

Best regards, Sebastien.

Note for me:

$('#DialogTag').keypress(function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
          //Close dialog and/or submit here...
    }
});

sebfz1 avatar Jan 15 '14 16:01 sebfz1

Hi actually, you can do it in wicket way :) no js something like that works for me (code in a class extending InputDialog):

    this.getForm().add(new AjaxFormSubmitBehavior(this.getForm(), "submit")
    {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target)
        {
            super.onSubmit(target);
            InputDialog.this.onSubmit(target);
            for(DialogButton button : getButtons())
            {
                if(button.match(DialogButtons.OK.toString()))
                {
                    InputDialog.this.onClick(target, button);
                }
            }

        }
    });

tszpinda avatar Jan 15 '14 20:01 tszpinda

Hi,

That's another approach, well done! I will think further on this topic probably next week...

Thanks & best regards, Sebastien.

sebfz1 avatar Jan 15 '14 22:01 sebfz1

How well does this work with nested forms, as I can't seem to stop it submitting it. I return false in wantSubmitOnParentFormSubmit() for the nested form, and yet, it still executes a non-ajax submit on the nested form.

Jezza avatar Jul 29 '16 10:07 Jezza

Hi,

I assume that's because the "submit" event is attached to AjaxFormSubmitBehavior... There is several ways to cancel to normal submit, but these should be tested in this specific case:

protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
    super.updateAjaxAttributes(attributes);

    // do not allow normal form submit to happen
    attributes.setPreventDefault(true);
}
@Override
public CharSequence getCallbackFunctionBody(CallbackParameter... parameters)
{
    return super.getCallbackFunctionBody(parameters) + "return false;";
}

Best regards, Sebastien.

sebfz1 avatar Aug 02 '16 10:08 sebfz1