Hi,

To anybody interested, I've found a workaround that worked.

I've added an invisible link into the dialog and simulated clicking on it:

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.

I hope that wiQuery will have a more general solution for that, but that's
something to be handled in wiQuery.

Regards,

Andrew

--
Andrew Schetinin


On Wed, Jul 17, 2013 at 6:41 PM, Andrew Schetinin <[email protected]>wrote:

> Hi Sebastien,
>
> I've tried it - used getCallbackFunction() - but it generated a function
> inside function, and broke JS syntax.
>
> I've tried a couple of other ideas, but none worked.
>
>
> Regards,
>
> Andrew
>
> --
> Andrew Schetinin
>
>
> On Wed, Jul 17, 2013 at 1:54 AM, Sebastien <[email protected]> wrote:
>
>> Hi,
>>
>> I think the idea is more to replace
>> wicketSubmitFormById('form','" +formAjaxBehavior.getCallbackUrl() +"',
>> null, null, null, null,null);")));
>> by
>> formAjaxBehavior.getCallbackFunction()
>>
>> With the override mentioned bellow.
>> #getCallbackFunction() will get you the ready-to-use javascript function.
>> I
>> am not a wiQuery expert so I don't know where exactly you have to use this
>> statement... (something like new JsScope(statement)?)
>>
>> Maybe Ernesto or Hielke may help you more on this...
>>
>> Best regards,
>> Sebastien.
>>
>>
>>
>> On Tue, Jul 16, 2013 at 6:06 PM, Andrew Schetinin <[email protected]
>> >wrote:
>>
>> > Hi Sebastien,
>> >
>> > Thank you for the suggestion, but the trouble with the sample (and
>> wiQuery)
>> > is that DialogButton is not a wicket component - it is a very simple
>> > object. There is no updateAjaxAttributes() to change.
>> >
>> > As I explained, the form submit there works by a plain call from
>> > JavaScript, and that call does not work anymore because of the missing
>> > wicketSubmitFormById() function.
>> >
>> > It seems to me that the only way to extend Dialog in wiQuery is through
>> > JavaScript - at least everything related to reaction on the button
>> clicks.
>> >
>> > Regards,
>> >
>> > Andrew
>> >
>> > --
>> > Andrew Schetinin
>> >
>> >
>> > On Tue, Jul 16, 2013 at 6:33 PM, Sebastien <[email protected]> wrote:
>> >
>> > > Hi Andrew,
>> > >
>> > > You have to override your ajaxbehavior#updateAjaxAttributes()
>> > >
>> > > protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
>> > > {
>> > >     super.updateAjaxAttributes(attributes);
>> > >
>> > >     attributes.setMethod(Method.POST); //if you wish to post
>> > >     attributes.setFormId("yourFormId");
>> > > }
>> > >
>> > > Best regards,
>> > > Sebastien.
>> > >
>> > >
>> > > On Tue, Jul 16, 2013 at 5:21 PM, Andrew Schetinin <
>> [email protected]
>> > > >wrote:
>> > >
>> > > > Hi,
>> > > >
>> > > > I've just upgraded from Wicket 1.4 to 6.9, and (among lots of other
>> > > > problems) 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/main/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.
>> > > >
>> > > > The question is - how is it possible to submit a form from JS?
>> > > >
>> > > > Regards,
>> > > >
>> > > > Andrew
>> > > >
>> > > > --
>> > > > Andrew Schetinin
>> > > >
>> > >
>> >
>>
>
>

Reply via email to