DatePicker value after manual input - javascript

I'm using a 0:dd/MM/yyyy as format and textTemplate for the DatePicker object
$('#datePickerSelector')`.shieldDatePicker({
format: "{0:dd/MM/yyyy}",
textTemplate: "{0:dd/MM/yyyy}"
});
When the user select the date from the selector in the proper way the format is correct when I retrieve the value using:
$('#datePickerSelector').val();
But whenever the user manually type in the date in the text box (for example 1/5/2015, the value retrieved using the same sentence above is (05/01/2015).
How can I fix this?

You need to use the parseFormats option of the datepicker. It contains an array which contains list of date formats used to parse the value set with value() method or by direct typed user input. In your case you need to add dd/MM/yyyy in the array:
$('#datePickerSelector').shieldDatePicker({
format: "{0:dd/MM/yyyy}",
textTemplate: "{0:dd/MM/yyyy}",
parseFormats: ["dd/MM/yyyy"]
});

Related

Unable to set datefield value

I have a form with several fields. One of those fields has xtype of datefield. Values for this form come from a json file, which looks like so:
{"field_1":"text value", "field_2": "2017-08-16T21:00:00.000Z"}
However, when I do:
form.setValues(json);
only the first field is set. The second datefield, which is defined like:
{
"xtype":"datefield",
"name": "field_2"
}
is not set for some reason. What is wrong with that and how can I fix it?
Because JSON does not support javascript dates natively, the value in field_2 is a string, not a javascript date.
While a string can represent a date, there are a variety of formats. In this case the string is in a format unrecognized by datefield. When the datefield tries to set the value, it will try to parse the string into a date, but since your selected format is not one known to datefield by default, the value is set to null.
The format and altFormats configs contain the formats datefield recognizes, and can be exchanged/amended to contain the date format(s) you want to support.

date string doesn't show up in date input

I have saved date as a string.
for example:
I have object in angularJs called myBirthday.
myBirthday.date="1996-04-04";
and I want to show the date in input in the modal:
<input type="date" ng-model="myBirthday.date" />
The problem is that it's shown dd-mm-yyyy instead of 04-04-1996.
Then When I change the date,close modal and then reopen it,The input shows the correct date.
How can I make it to show the correct date? not dd-mm-yyyy?
I have tried almost every string types of date.
please HELP
You shoud create a Date object instead of a String.
myBirthday.date = new Date(1996, 3, 4);
You could also cast the Date to a String:
date_string = myBirthday.date.toISOString();
It seems date filter called before binding of date or date-format values. date/dateformat is null initially but filter called that's why filter would be giving default format string. And once values are binded properly then everything works perfectly fine

Want to convert String data type into Date data type in pentaho

I have a string which has a date in this format: n_date=2014-04-20
I want to convert it into date data type
var Final_date = str2date(n_date,"yyyy-MM-dd");
but I get an error.
I'm do this in pentaho
You don't need a Java script step to do that. It's much easier and faster to use a calculator step or a select values step instead:
1) Calculator step: Create a new field, Final_date as a Copy of field A; on Field A put the name of your input string; Data type is date and on Conversion mask choose the yyyy-MM-dd format (you don't have to pick one from the dropdown menu, you can write your own);
2) Select values: on the Metadata panel, choose your input field and Date as the data type; as above, fill in the date format your data comes in.
The difference between 1) and 2) is that in the 1st case you get a new field of the Date type, whereas in the 2nd case you change the data type of the input field.

Knockout.js input type date data binding in Google Chrome

I'm struggling to set a value on the input of type="date" in google chrome: http://jsfiddle.net/ruslans/gNv7H/
<input data-bind="value: dateString" type="date"></input>
var viewModel = {
someDate: new Date(parseInt("/Date(1367708400000)/".substr(6)))
};
ko.applyBindings(viewModel);
My date will come from JSON data but first I need to find out which format does it need to be in for Chrome's date picker to recognize the binding. Would I have to do it with jQuery selector and set .val() on the field? Seems daft...
Edit: according to this article, the date format to set the value on Google date input must always be "yyyy-mm-dd". Which is a pitty, because we're using jQuery date picker for all browsers where there's no native date pickers exist.
You just need to correctly format your value as described in the W3C working draft:
A valid full-date as defined in RFC 3339, with the additional qualification that the year component is four or more digits representing a number greater than 0.
Example:
1996-12-19
So the following should work:
var viewModel = {
dateString: ko.observable('2002-02-02')
};
Demo JSFiddle.

in javascript onchange i wish to convert date input numeric (01022013) to date format )01/02/2013)

i want to create a form where user enter 01022013 format and onchange it should convert to date format . and similarly onfocus it should be in numeric format.
pl help.
Try this:
'01022013'.replace(/(\d{2})(\d{2})(\d{4})/, '$1/$2/$3') // -> "01/02/2013"

Categories

Resources