[Play-1.2.5.3] How insert jQuery DateTime picker in the form

151 views
Skip to first unread message

sana baccar

unread,
May 27, 2014, 6:20:31 AM5/27/14
to play-fr...@googlegroups.com
Hi,

I aim to insert DateTime picker in my form but it didn't work with me.
Are there libs or something similar that i should insert? I integrated the stylesheet  and the java script files. I am using Play-1.2.5.3 and it includes iquery-1.6.4.min.js.

Cheers,
Sana

Mariusz Nosinski

unread,
May 28, 2014, 2:21:38 AM5/28/14
to play-fr...@googlegroups.com
Hi, I've used Datepicker with play 1.2.7, but I was using twitter bootstrap for styling. I was using plugins:

On the model side I was using Joda time with hibernate http://joda-time.sourceforge.net/contrib/hibernate/

Model - definition of field:
 
 @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
   
public DateTime dateFrom;


   
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
   
public DateTime dateTo;


javascript part: 
 $('.datePicker').datepicker({'weekStart': 1});



Controller part is  standard controller, all data should be set automagically.

public static void doAddHoliday(@Valid Holiday holiday) {
       
if (validation.hasErrors()) {
           
params.flash();
            validation
.keep();
            addHoliday
();


       
} else {
            holiday
.save();
            flash
.success("holiday.add.success");


       
}
        index
();
   
}


but if doesn't, you can catch it separately:
Example from another controller: 

public static void doNewLoan(Long id, @As("dd-MM-yyyy") DateTime dateFrom, @As("dd-MM-yyyy") DateTime dateTo,




View Part:

<div class="controls">
               
<input type="text" size="30" name="holiday.forDay" class="input-small datePicker" id="holiday_forDay"
                       
value="${org.joda.time.DateMidnight.now().withDayOfWeek(org.joda.time.DateTimeConstants.SUNDAY).toString("dd-MM-yyyy")}"
                       
data-date-format="dd-mm-yyyy" >


</div>

 

value is set to next sunday for default.

Catch this!!!!!:
date format at java and javascript aren't the same if you want to format date as day-month-year in the java part You use "dd-MM-yyyy" but in the javascript "dd-mm-yyyy"! Small doubleM in java will be treated as minutes not months.


Hope this help
Reply all
Reply to author
Forward
0 new messages