rasyahadlinugraha / wiquery

Automatically exported from code.google.com/p/wiquery
MIT License
0 stars 0 forks source link

Submitting forms from within the Dialog seemed to stop working in Wicket 6.9 #269

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've just upgraded from Wicket 1.4 to 6.9, and I have a trouble with porting 
the code that submitted a form from within a wiQuery dialog.

My code is based on the sample that can be found here:
http://code.google.com/p/wiquery/source/browse/examples/wiquery-examples/src/mai
n/resources/org/odlabs/wiquery/examples/dialog/DialogPage.java?r=407

The trick here was that the Dialog contains a form which has to be submitted 
when OK button is clicked, and that was done with the following code:

                buttonsAdv.add(new DialogButton("Save",
                                JsScope.quickScope("wicketSubmitFormById('form','" +
                                                formAjaxBehavior.getCallbackUrl() +
                                                "', null, null, null, null, null);")));

Unfortunately, in Wicket 6.9 this code fails to find the function  
wicketSubmitFormById()

I also have a feeling that in my previous attempt to port this code to Wicket 
6.6 the same functionality worked fine.

I've tried several ways to submit the form from within a dialog, but none 
worked. Meanwhile I'm waiting for an answer from the Wicket mailing list, and 
also posting a ticket here, because I believe that the mentioned sample is 
broken.

I also have a general suggestion - for example in wicket-jquery-ui they have 
much better Dialog support - with forms and whatever one wants. Here in wiQuery 
the Dialog is very limited, and requires such JS tricks to submit forms. It 
would be good to improve forms support in Dialog component.

Original issue reported on code.google.com by ascheti...@gmail.com on 16 Jul 2013 at 3:27

GoogleCodeExporter commented 9 years ago
Hi,

These examples are rather old and wicket JavaScript API has changed a lot from 
1.4.x to 6.x. I do not think these examples ever where migrated to 6.x. In fact 
they where dropped from wiquery on 1.5.x branch. Wiquery development have moved 
to github  

Original comment by reier...@gmail.com on 18 Jul 2013 at 6:59

GoogleCodeExporter commented 9 years ago
Thank you for your comment.

Unfortunately, marking this ticket as invalid does not solve my problem :-)

That sample was the only way to implement a dialog with a form using wiQuery, 
and as you say starting from 6.0 such a feature is not supported anymore in 
wiQuery. Isn't it a regression?

I'll try replacing wiquery with wicket-jquery-ui - the dialog there is much 
more functional.

Original comment by ascheti...@gmail.com on 18 Jul 2013 at 8:02

GoogleCodeExporter commented 9 years ago
No want I say is that this a code on an example.... and those examples are no 
longer part of wiquery. And the JavaScript API of wicket have changed. If you 
describe what you are trying to achieve I could try to see how to achieve that 
on WiQuery 6.x

Original comment by reier...@gmail.com on 18 Jul 2013 at 8:53

GoogleCodeExporter commented 9 years ago
As I said - my case is exactly the same as in that sample.

I have a Dialog with a complex Form inside. 
And I want, when Ok is clicked, to submit the form data.

Previously it worked fine with that function wicketSubmitFormById(), but in 
Wicket 6.9 the function does not exist anymore, and none of Wicket 6 approaches 
worked.

Original comment by ascheti...@gmail.com on 18 Jul 2013 at 9:01

GoogleCodeExporter commented 9 years ago
I will have a look... and see if I can add something to wiquery to make this 
use case easier to implement. Reopening the issue

Original comment by reier...@gmail.com on 18 Jul 2013 at 9:07

GoogleCodeExporter commented 9 years ago
I found a workaround that works.

I've added an invisible link into the dialog:

HTML code for the link:

<a wicket:id="submitFormInvisibleButton" style="visibility: collapse;" />

Java code for the link:

submitLink = new AjaxSubmitLink( "submitFormInvisibleButton", form ) {
    private static final long serialVersionUID = 1L;

    @Override
    protected void onSubmit( AjaxRequestTarget target, Form<?> form ) {
        super.onSubmit( target, form );
        form.onFormSubmitted();
        if( form.hasError() ) {
            logger.debug( "AjaxSubmitLink.respond() error" );
        } else {
            logger.debug( "AjaxSubmitLink.respond() onOK" );
            onOk(target);
        }
    }
};
submitLink.setOutputMarkupId( true );
form.add( submitLink );

JavaScript to be added to the OK button:

sb.append( "$('a#" ).append( submitLink.getMarkupId() )
    .append( "').triggerHandler('click');" );

That worked - good enough for me.

Anyway, I'd recommend to have a generic solution for this use case - it should 
be quite common, IMHO.

Original comment by ascheti...@gmail.com on 18 Jul 2013 at 9:43