Play + Bootstrap + Dates


First of all, I hate HTML date input fields, because they're so broken when you start playing with different formats for different locales, and HTML5 input=date doesn't help either since not all browsers implement this and in case of Google's Chrome, it's so ugly that you won't use it.
To try to cope with this I'm using this date picker for Bootstrap which handles things pretty well until you hit a wall with how Play handles form data for dates. Basically, the problem is that even if your form class has a Date field and you registered a custom formatter as explained here, the Date value is not formatted when the template is rendered. Some code to explain

public class MyForm {
    public LocalDate myDate;
}

In the controller you would have something like:

MyForm myForm = new MyForm();
myForm.myDate = new LocalDate();
return ok(
    views.html.somePage.render(
        form(MyForm.class).fill(myForm)
    )
);

If you try to use the value from this form you'll see that it follows the ISO format yyyy-MM-dd, which is fine, until you're asked for this field to follow specific locale formats like dd/mm/yyyy or mm/dd/yyyy.

To fix this I've created my own implementation of the inputDate template:



No hay comentarios:

Publicar un comentario