I have the following datepicker in a form
<g:datePicker name="born" default="none" precision="day"
noSelection="['':' ']" relativeYears="[-25..2]"
value="${animalInstance?.born}" />
Since I allow a no selection in the datepicker it's possible to enter a date with no days, no months but a valid year. It's exactly the intended behavior.
But the params come in the following format
born=""
born_year="1995"
Controller and Command object do not bind this correctly and the whole date is considered null.
Is there a proper way to handle this without doing some If...Then...Else code?
Related
I' have 2 text fields 1st one for giving date from and the other one for date to, what i want is while i'm selecting date from using 'calendar:datePicker' the dates before current date must be disabled and if i have selected a date 1/6/2014 in 1st text field, when i select the date to from the 2nd one the dates before 1/6/2014 must be disabled how can i achive this..?
From<calendar:datePicker name="datefrom" years="${2014..2017}" value="${new Date()}" defaultValue="${new Date()}"/>
To<calendar:datePicker name="dateto" years="${2014..2017}" value="${new Date()}" defaultValue="${new Date()}"/>
That looks like an old plugin and it might not have the option that you need.
Use jQuery UI instead: http://jqueryui.com/datepicker/#date-range
jQuery UI has a grails plugin as well. http://grails.org/plugin/jquery-ui
The situation
I want to use ui-date to set/edit a date in my app. I use the latest stable versions of angular, angular-ui, jquery-ui etc.
The problem
As soon as a date is selected using the datepicker the date in my model will equal the selected date minus 1 day. It will also get send to my server and saved in my database this way.
The plunker
http://plnkr.co/edit/Ft14Wa?p=preview
Initially the date in the datepicker input and the date in my model are the same. After picking a date they differ.
The question
What is going (wr)on(g) here???
ui-date expects your model to be an actual date object. In your case it's a string. If you take a look at the console you'll see that angularUI actually informs you about that. Then it advises you to add additional ui-date-format tag with the specified date format with which your date string will be parsed into date object.
Long story short, your need to adjust your input as this:
<input ui-date="{dateFormat: 'yy-mm-dd'}" ui-date-format="yy-mm-dd" ng-model="customer.contract_end_date"></input>
Working plunker.
this solves my problem.
angularjs uses default timezone which considers hour time. seting timezone option of ng-model to UTC clear hour times......
ng-model-options="{timezone:'UTC'}"
The problem is that angular is using its default timezone when parsing the date selected on the datepicker. To resolve the issue you can use the ng-model-options directive which accepts a "timezone" parameter.
<input type="text" ng-model-options="{timezone:'UTC'}" ... >
I set date format as dd-mm-yyyy as my requirement. then set date-type as string.
<input type="text" class="form-control col-xs-9"
data-date-format="dd-MM-yyyy" data-autoclose="1"
ng-model="modelName"
date-type="string" bs-datepicker required>
We're working on a .NET MVC mobile site. I understand that on the iPhone, mobile safari will display a datepicker for the following input field:
<input type="date"/>
We have a standard date picker helper which spits out date picker options for various platforms. In this case we detect mobile safari and then write out an input field that is bound to our model:
<input name="StartDate" value="2008/12/21" type="date"/>
The problem is that the value portion is not shown on load. We can enter in new values, and save them back to our database. But then when we reload the page those values don't show up in the fields. If we save again, our values are all set back to null in the db.
I noticed that when you select a date with the wheels on the iPhone, the value of the text field ends up in the format similar to "Apr 6, 2012" where as I'd expect it to show 2012/04/06 or 04/06/2012.
My guess is that the mobile safari displays a different attribute of the field, and then sets the value attribute appropriately behind the scenes.
Does anyone know what's going on with this? Thanks!
AFAIK the date must be RFC3339 compliant. Have you tried 2008-12-21 (dashed instead of slashes)?
<input type="date" value"yyyy-MM-dd" />
I'm struggling with a Struts2 date formatting issue. If I understand correctly, type conversion in Struts2 is locale aware, and any form fields/parameters that map to Date objects should be strings formatted in their Locale specific SHORT format; the default output for a Date object on the value stack is also output as the Locale specific SHORT format (unless overridden with custom formatting).
Although form fields have worked fine with dates, when using the <s:url> tag I can't seem to get the <s:param> tag to encode date parameters correctly. When I try something such as this
<s:url action="foo" >
<s:param name="endDateParam" value="#endDate"/>
</s:url>
the result is pretty obviously not the SHORT format:
/foo.action?endDateParam=Sat+Jan+14+00%3A00%3A00+EST+2012
I re-read the Struts2 documentation but they mostly discuss creating custom date formats in the i18n'ized properties files, which doesn't seem like the right solution.
Any help with this problem would be greatly appreciated.
You can send it like that :
<s:param name="dateFrom">
<s:date name="dateFrom" format="dd.MM.yyyy"/>
</s:param>
You've probably already solved this by formatting a string in the action the way you need it. This I would advise first, unless you are supper stickler for model/view separation or there isn't a one to one mapping between the action and the view in which case this zealousness my be justified.
Lets say you felt the formatting wasn't the business of the action in that case you could use OGNL to it's full effect:
Here is an example that displays the current date (it uses new to construct a new date but you can very easily just replace "new java.util.Date()" with "endDate". It was constructed this way so anyone can just paste it into their JSP without any action dependencies.
<p>
<s:property value="#java.text.DateFormat#getDateInstance(#java.text.DateFormat#SHORT, #java.util.Locale#CANADA).format(new java.util.Date())"/>
</p>
NOTE: requires OGNL static method access to be true. Easiest way to do that is to add the following to struts.xml:
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
Using OGNL to this level is a bit suspicious but it is easy to read and the intention is clearly view/presentation related. Although it isn't that easy to construct... The easiest way is to write everything as one line of java and then apply ognl syntax rules which you would find here:
http://commons.apache.org/ognl/language-guide.html
Also for quick reference:
http://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html
http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html
That is basically my question. It is showing me today's date and not a blank or null or '' date, even if I put null or '' it runs perfectly but keeps showing me today's date, not a blank dropdown box. So I want to change the default to being blank when the gsp loads, not with today's date.
Thanks
The usage of the attribute default is not documented in the Grails documentation but its functionality can be extracted from the implementation. Use the attribute default="none"to stop the datePicker from using the current date and provide an empty text as the noSelection value:
<g:datePicker default="none" noSelection="['':'']" />
More information about the attribute noSelection can be found in the Grails documentation.