javascript - Using dijit.form.DateTextBox Not able to retain proper Time value -
i using dijit.form.datetextbox update date field.
<form:input id="date_id" name="date_field" path="createdate" dojotype="dijit.form.datetextbox" disabled="false" constraints="{datepattern:'dd/mm/yyyy hh:mm:ss.ss'}" invalidmessage="invalid" promptmessage="invalid" lang="en-us" required="true"/>
now, suppose if 'createdate'
value '05/01/2012 21:10:17.287'
, displaying '05/01/2012 12:00:00.00'
in date text box.
due which, while editing field, i'm not able keep was.
is there anyway can retain time part '21:10:17.287'
.
kindly suggest.
(this solution work above dojo 1.6 versions )
the default datetextbox
overrides old value when setting new one. means time context lost while setting value. if want make possible, have extend default behavior of _setvalueattr
function of datetextbox
since setter of value
field.
this how this:
declare("custom.datetextbox", [datetextbox], { _setvalueattr: function(value, prioritychange, formattedvalue) { if(value !== undefined){ if(typeof value == "string"){ value = stamp.fromisostring(value); } if(this._isinvaliddate(value)){ value = null; } if(value instanceof date && !(this.dateclassobj instanceof date)){ value = new this.dateclassobj(value); } } if (value != null && this.value != null) { value.sethours(this.value.gethours()); value.setminutes(this.value.getminutes()); value.setseconds(this.value.getseconds()); value.setmilliseconds(this.value.getmilliseconds()); } this.value = value; this.inherited(arguments); } });
what happens here pretty easy, first thing parsing new value valid date
. before replacing original value i'm copying time fields (hours, minutes, seconds , milliseconds).
i made jsfiddle demonstrate this.
Comments
Post a Comment