You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Levy <je...@gmail.com> on 2011/04/27 00:50:30 UTC

AjaxButton and HTML5 fields

I've extended TextField to support some of the HTML5 variants, number, email
etc.  This works great when submitting via normal methods.  However it
doesn't work when using AjaxButton, the form data for the HTML5 fields is
never POSTed.

The root issue appears to be in wicket-ajax.js specifically lines 461-471
(Wicket 1.4.17):

// this function intentionally ignores image and submit inputs
Wicket.Form.serializeInput = function(input) {
    var type = input.type.toLowerCase();
    if ((type == "checkbox" || type == "radio") && input.checked) {
        return Wicket.Form.encode(input.name) + "=" +
Wicket.Form.encode(input.value) + "&";
    } else if (type == "text" || type == "password" || type == "hidden" ||
type == "textarea" || type == "search") {
        return Wicket.Form.encode(input.name) + "=" +
Wicket.Form.encode(input.value) + "&";
    } else {
        return "";
    }
}

As I understand this, basically the fields are ignored because they aren't
specifically handled in the code above... I've tested it by adding type
=="number" etc and that fixes the problem.  I suppose my question is, is
this the right place to fix it, and if so what is the best way to override
this function, without having to do the whole js file?

J

Re: AjaxButton and HTML5 fields

Posted by Jeremy Levy <je...@gmail.com>.
Thanks Martin, that worked beautifully, well perhaps not beautifully but
quite well.



On Wed, Apr 27, 2011 at 1:52 AM, Martin Grigorov <mg...@apache.org>wrote:

> Hi Jeremy,
>
> Yes, this is the way to make it working.
> In Wicket 1.5 all this is already improved and Wicket provides Number,
> Url and Range TextFields out of the box but it is quite easy to use
> the other types too.
> To make it work in 1.4.x you'll need to use the monkey-patch approach.
> You can see the history of
>
> https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/wicket-html5-parent/wicket-html5
> .
> There is a Behavior which did exactly this before the improvements in
> Wicket 1.5.
>
> On Wed, Apr 27, 2011 at 1:50 AM, Jeremy Levy <je...@gmail.com> wrote:
> > I've extended TextField to support some of the HTML5 variants, number,
> email
> > etc.  This works great when submitting via normal methods.  However it
> > doesn't work when using AjaxButton, the form data for the HTML5 fields is
> > never POSTed.
> >
> > The root issue appears to be in wicket-ajax.js specifically lines 461-471
> > (Wicket 1.4.17):
> >
> > // this function intentionally ignores image and submit inputs
> > Wicket.Form.serializeInput = function(input) {
> >    var type = input.type.toLowerCase();
> >    if ((type == "checkbox" || type == "radio") && input.checked) {
> >        return Wicket.Form.encode(input.name) + "=" +
> > Wicket.Form.encode(input.value) + "&";
> >    } else if (type == "text" || type == "password" || type == "hidden" ||
> > type == "textarea" || type == "search") {
> >        return Wicket.Form.encode(input.name) + "=" +
> > Wicket.Form.encode(input.value) + "&";
> >    } else {
> >        return "";
> >    }
> > }
> >
> > As I understand this, basically the fields are ignored because they
> aren't
> > specifically handled in the code above... I've tested it by adding type
> > =="number" etc and that fixes the problem.  I suppose my question is, is
> > this the right place to fix it, and if so what is the best way to
> override
> > this function, without having to do the whole js file?
> >
> > J
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Jeremy Levy

Re: AjaxButton and HTML5 fields

Posted by Martin Grigorov <mg...@apache.org>.
Hi Jeremy,

Yes, this is the way to make it working.
In Wicket 1.5 all this is already improved and Wicket provides Number,
Url and Range TextFields out of the box but it is quite easy to use
the other types too.
To make it work in 1.4.x you'll need to use the monkey-patch approach.
You can see the history of
https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/wicket-html5-parent/wicket-html5.
There is a Behavior which did exactly this before the improvements in
Wicket 1.5.

On Wed, Apr 27, 2011 at 1:50 AM, Jeremy Levy <je...@gmail.com> wrote:
> I've extended TextField to support some of the HTML5 variants, number, email
> etc.  This works great when submitting via normal methods.  However it
> doesn't work when using AjaxButton, the form data for the HTML5 fields is
> never POSTed.
>
> The root issue appears to be in wicket-ajax.js specifically lines 461-471
> (Wicket 1.4.17):
>
> // this function intentionally ignores image and submit inputs
> Wicket.Form.serializeInput = function(input) {
>    var type = input.type.toLowerCase();
>    if ((type == "checkbox" || type == "radio") && input.checked) {
>        return Wicket.Form.encode(input.name) + "=" +
> Wicket.Form.encode(input.value) + "&";
>    } else if (type == "text" || type == "password" || type == "hidden" ||
> type == "textarea" || type == "search") {
>        return Wicket.Form.encode(input.name) + "=" +
> Wicket.Form.encode(input.value) + "&";
>    } else {
>        return "";
>    }
> }
>
> As I understand this, basically the fields are ignored because they aren't
> specifically handled in the code above... I've tested it by adding type
> =="number" etc and that fixes the problem.  I suppose my question is, is
> this the right place to fix it, and if so what is the best way to override
> this function, without having to do the whole js file?
>
> J
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org