Question

I'm experimenting with HTML5. What I'd like to know is how does Wicket work with HTML5 input types such as date and email, if at all? Currently Wicket uses java script to generate a calendar for date inputs.

What complicates this issue is how would Wicket handle a browser that doesn't support HTML5 input tags of type date (and the other new HTML5 tags).

Was it helpful?

Solution

Wicket (1.5 and onwards) doesn't support input type='date' or similar constructs out of the box. There's a DateTextField in Wicket Extensions, but it doesn't specify type='date' (yet). I'd suggest creating your own implementations that properly set the type attribute (my guess to why they haven't been added to the field is that it would break existing applications).

There's EmailTextField, NumberTextField and others. These add the type attribute and validate the input on the server.

Browsers that don't support HTML5 inputs fallback to type='text', so for a Wicket point of view there's nothing different. Wicket will still validate the input according to the set rules.

OTHER TIPS

You just need override the method TextField#getInputType() and return "date" with that you skip the validation on the onComponentTag method from the TextField component. For example if you don't want to create your own component you can use an anonymous class like this:

        DateTextField dob = new DateTextField("dob", dobModel){
            private static final long   serialVersionUID    = 1L;

           /* (non-Javadoc)
            * @see org.apache.wicket.markup.html.form.TextField#getInputType()
            */
            @Override
            protected String getInputType()
            {
                return "date";
            }           
        };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top