Grails Timepicker - grails

I need to save Date Time in the (oracle) database in one column, which is sqlType of timestamp (looks like 01-JAN-14 12.00.00.000000 AM). While learning grails I've been using the Joda lib with it's "time picker".
The Joda timepicker has worked well, but now that I'm looking to go primetime I'm looking for something a little more user friendly. Frankly, text boxes might be more user friendly than the drops downs joda gives you.
Anyway, I'd like to remove joda and use something like this:
http://trentrichardson.com/examples/timepicker/
but I can't figure out how to implement it in grails. In my view, if I put:
<input type="text" name="endDate" id="endDate" value="${exampleInstance?.endDate}" />
in place of the g:datePicker, it works fine (the picker that is), except nothing gets saved to the database, and no errors are generated. I hit Save and the Show view comes up with an empty endDate field. Do I need more input tags?
Is there some easy way to implement a modern looking date+time picker that I've missed?
Furthermore, I see there is a plugin for this picker here
http://grails.org/plugin/jquery-ui-timepicker
But being that there isn't any documentation, I'm not sure how to use that either (?)
ANSWER
in controller save/update put something like:
def endDate = params.date('endDate', 'yy-MM-dd h:mm')
//println "Date from Picker was "+endDate
params.endDate = endDate
No further casting was necessary being that it ended up I could format the datepicker control to a very close format as what's in the database, but had I needed to cast from one odd format, or a string, to another, I toyed with this code, which is more psuedo than anything as I was thinking through the process (I'm sure there's a totally Groovy way to do this same thing):
SimpleDateFormat inputFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss.S");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy h.mm.ss.S a");
def v = params.endDate
Date date = inputFormat.parse(v);
String temp = sdf.format(date)
Date dateOut = sdf.parse(temp)
println dateOut

The datepicker, is your UI component therefore, you can have any library that you wish for UI and anything else for back-end. Mostly they are easy to implement, if they provide a little bit of documentation!!.
The timepicker for jQuery ui plugin, that you provided the link, is exposing a resource called jqueryUiTimePicker which depends on jQuery and jQuery-ui. So simply by including this resource into you resources configuration you should be able to utilize it. Its no different than defining your own resource and use it.
About saving issue that you have, on your save pass parameter failOnError:true so you can see the errors if any.
I have created a sample project that utilizes this plugin hope it helps

In your controller, you will need to parse the parameter value to a Date value. Something like,
def endDate = params.date('endDate', 'dd-MM-yyyy')
dd-MM-yyyy is whatever format the jquery plugin submits the date value. (println params for this or look up the plugin documentation)
If you want a date format binding to happen automatically, check the Date Formats For Data Binding in the doc http://grails.org/doc/latest/guide/single.html#dataBinding for a way to globally specify the format

Related

Formatting Orbeon Date input fields

I am trying to format an input field of the type xs:date in Orbeon.
I have tried using the xxf:format attribute, but the datepicker can not understand the date when it has been modified.
The idea now was to change the javascript of Orbeon to use the xxf:unformat attribute to interpret the date and transform it back to ISO format.
I've tried changing the data.js but for some reason none of the changes can be seen.
Am I changing the wrong file?
Edit
I figured out that the xforms.js has a function 'getCurrentValue' which is being as the changes I do there are visible. Now I just need to figure out who is the one that's calling the function.
Edit:
It is the Calendar who requests the value of the input when the user clicks on the symbol. This all happens at the client side, and the generated HTML does not have the format/unformat attributes. However I want to use their value. Can I make a request to Orbeon to get it? How?
In case you're using an xf:input bound to a node of type xs:date, you can control the formatting of the date field with the oxf.xforms.format.input.date property. A few formats are supported, and if you want to add more, the best would be to follow the pattern currently used for the currently supported formats.
E.g.
[M]/[D]/[Y]
[Y]-[M01]-[D01]

x-editable with meteor textarea no line breaks and date timezone issue

I'm currently trying to work in bootstrap x-editable to my meteor application. I'm using the atmosphere package for this: https://github.com/nate-strauser/meteor-x-editable-bootstrap. I'm having a couple of issue so far which are:
When I select a date using the date data-type I get a javascript date object back that is 4 hours behind what I actually picked(assuming this is because I'm in -4 timezone).
When I edit a textarea, the line breaks are saved to the database, but when bring up the editable to edit it the line breaks are striped.
It looks like this might be the intended behavior. Its hard to be sure without more information.
With the date, javascript stores date in unixtime. This is because its very easy to switch timezones and not worry about having javascript itself having to keep track of DST and the other complications of keeping time.
If you use new Date(<the javascript timestamp>); you should get the time in your timezone.
With the textarea it looks like some kind of text-encoding conversion is taking place. You should check to see what the character codes of those stripes are and convert them to newlines like \n. One scenario this could occur is if you're copy-pasting stuff with a different encoding into the textarea.

Orbeon form builder: Using date fields with initial value "current-date()"

I am using date fields in Orbeon form builder that should be prefilled with the current date (see http://i42.tinypic.com/erdjrb.jpg). When choosing a date by hand in the form, the date format in resulting XML model is set to "2011-07-12". But when not changing the default value of current-date(), then I get "2011-07-12+02:00". Does anybody know why the date format is different when I prefill it with current-date()?
Thank you!
The XPath function fn:current-date() by definition returns the date together with explicit time zone information. I assume orbeon just passes the function call to the XPath engine (Saxon i think). A quick workaround would be to format the result of current-date() using format-date(), for example:
format-date(current-date(), '[Y]-[M01]-[D01]')
Since i don't use Form Builder, i can't tell in detail, but i assume setting the config options how to format xforms:input controls regarding date and time values applies for form builder, too.

Handling different date formats in ROR

I am trying to build a ROR app that allows users to enter date in various formats such as 12/31/11 (month/day/year) or 31/12/11 (day/month/year). In order to interpret date format, I will have a select field from where user can select the format of date. I can use Date.strptime(value, format).to_s() in controller before saving record.
However, I am not sure is controller right place to put this information. Is there a way I can push this to model..say in before save method.
You could just save the data as it is (in the controller), and have another field in the model telling it how to interpret the data. Then, in a before_validation callback, you could try parsing the date according to the given format and writing it to the same field, now as a date. Problems may arise on the way back. Then, to display it in the view again, you could write helpers - but better yet, provide a method in the model (for instance, formatted_date) that will compute and display the date.
However, this requirement sounds strange. Why is the user's responsibility to select a date format? Shouldn't it be based on the user locale?
In any case, I suggest you register your date formats in an initializer, rather than repeting the format strings throughout the application.

ASP.NET MVC Calendar Design

I want to design a calendar in asp.net mvc and I want to take month information as a string in address bar. What should I do? And after that I have to show this month from index.aspx. How can I do this?
It's a little unclear what you're trying to do. If you're trying to present a calendar so that a user can input a date, I'd use jQueryUI's datepicker. The default style looks pretty nice, it's simple to use, and it works really well.
After re-reading your question, it seems you want your URL to be in some sort of date format. If this is the case, you need a custom route, like the one in this article. After you have created your custom route, printing the date is rather simple: pass the month part of the date from your controller down to your view and display it.

Resources