AngularJS/HTML input week format error - javascript

I'm using AngularJS to for user to choose week from a input week tag, but there is something bizarre qbout the format.
I've read that the format should be yyyy-W##, and I do this already, but angularJS still gives me this error:
Error: [ngModel:datefmt] Expected `2015-W51` to be a date
http://errors.angularjs.org/1.4.8/ngModel/datefmt?p0=2015-W51
and this is my tag:
<input type="week" ng-if="header.type==='week'" ng-model="entry[header.className]" ng-change="vos.fieldSelectionChanged(field_id,entry.record_id)"/>
So as you see, the input type is week, here, I'm using this tag inside of a ng-repeat, so I'm loading the data from the entry[] array, and the week loaded is 2015-W51.
So please tell me what I'm doing wrong , is there a best practice using this tag with AngularJS?
Thanks !
Edit 1 - more code
I've found this:
http://codepen.io/empirefox/pen/MYyoao
It demonstrates how to use input week with a date, but the problem is that I don't have the data as dates.
And at the right part of the page, you have this :
$scope.value = new Date(2013, 0, 3);
Change it to this :
$scope.value = "2015-W20";
And it gives me the same error. So if we can solve this one, I think we can also solve the problem on my page.

Angular uses native Date object to handle all its datetime-related inputs, but unfortunately Date instances does not have any methods to handle week numbers. It would be the best solution to stick with moment.js.
Coercion from string to ng-model-enabled value (in controller etc.):
$scope.value = moment("2015-W20").toDate();
Coercion from ng-model-enabled value to string (in form submit handler etc.):
moment($scope.value).format("YYYY-[W]WW"); // returns "2015-W20"

Related

GroupBy Filter in AngularJS

I have an array of timeline which I want to divide in groups per date (dd/MM/YYYY). I was trying make my own "groupBy" without any library (which I really prefer), but I got no success. So I decided to search for a library that does it and I found this: angular-filter, so now I'm trying to use it.
The problem is that I can't figure out what I'm doing wrong, I followed this example and created my JS Bin to ilustrate my situation. It always says the format date is wrong, why?
By the way, the expected result is:
Date: 17/06/2016
Timeline item: an e-mail edited
Timeline item: an e-mail deleted
Timeline item: an e-mail edited
Date: 18/06/2016
Timeline item: an e-mail added
Timeline item: an e-mail added
Filters in Angular are called many times, not just once. So during the first digest, your created_at values are converted to D/M/Y format. Then, when during the next digest Angular call your filters again, it tries to create a date with already converted value (i.e. new Date('18/06/2016')). So you get an Invalid date as a result.
The solution is to convert the dates once in the controller before assigning them to the view and omit the map: ... filter.
See the updated jsbin.

Angularjs fullDate filter not working

I'm getting following error on using fullDate filter inside my html:
Error: [ngModel:nonassign] Expression 'publisherForm.dt |
date:'fullDate'' is non-assignable. Element:
Here is my jade code:
datepicker.well.well-sm(ng-model="publisherForm.dt", show-weeks="false", min-date="minDate")
input.form-control(type="text", ng-model=" publisherForm.dt | date:'fullDate' ", readonly='')
what I'm trying is show the selected date from ui-datepicker to user in another input field. Since I want to show only date, I'm using fullDate filter but in console I'm getting above mentioned error.
Any idea what can be the possible reason ?
On searching through existing threads on SO, I found following threads which helped me to solve my problem:
Using angularjs filter in input element
How to format a date using ng-model?
AngularJS get formatted date in ng-model
Finally made following lines of code change and it started working fine for me:
$scope.$watch('publisherForm.dt', function(newVal){
$scope.publisherForm.formattedDate = $filter('date')($scope.publisherForm.dt, 'fullDate');
});
If there is anyone who can suggest a better solution is always welcome.
Thanks

How to set date/time field in netsuite with suitescript

var curRate = nlapiCreateRecord("customrecord_currency_exchange_rates",{recordmode: 'dynamic'});
serverDt = "09/25/2013 06:00:01 am"
var timezone = compConf.getFieldText('timezone');
curRate.setDateTimeValue('custrecord_effective_date' ,serverDt ,timezone);
nlapiSubmitRecord(curRate);
Hello I try to set custrecord_effective_date field which is a date/time type. But after the execution it gives an error below.
How can I set this field?
thanks for help.
INVALID_FLD_VALUE You have entered an Invalid Field Value 09/25/2013 06:00:01 am for the following field: custrecord_effective_date
Although this is an old post and the original question is about SuiteScript 1.0, I came across this page looking for the same INVALID_FLD_VALUE error with the date/time field but in SuiteScript 2.0, and since the solution ended up being different I wanted to share it for future readers.
In SuiteScript 2.0, setting a date/time field simply requires a JavaScript date object. Below is an example within a before submit user event context.
context.newRecord.setValue({
fieldId : 'custrecord_myfield',
value : new Date()
});
For setting Date/Time Field values using SuiteScript 2.O.
First Use 'N/format' module and 'N/Record' Module.
Create a normal Javascript Date Object.
Format the Date Object to DateTime Object.
And use Record.setValue() method for setting the datetime value.
Example:
var d = new Date();
var formattedDateString = format.format({
value: d,
type: format.Type.DATETIMETZ
});
record.setValue('yourDateTimeFieldId',formattedDateString );
For anyone that may be stuck with a SuiteScript 1.0 script trying to populate a date/time field and the existing solutions don't work for you, you can try using NetSuites nlapiDateToString method. Apparently the date/time field wants a string.
Example:
var record = nlapiCreateRecord('your record type');
record .setFieldValue('your date field id', nlapiDateToString(new Date(), 'datetimetz'));
nlapiSubmitRecord(record, false, true);
The SuiteScript 1.0 reference for more detail:
Hi thanks for answers after posting the question i checked the Form of record type and when i checked for the field 'custrecord_effective_date' I noticed that the date format must be 'DD/MM/YYYY HH:MM:SS' so when i changed it worked.
If you look at the NetSuite WSDL file, you will find the dateTime declaration:
<xs:simpleType name="dateTime" id="dateTime">
<xs:documentation
source="http://www.w3.org/TR/xmlschema-2/#dateTime"/>
Go to the URL and look at the source:
3.2.7 dateTime
[Definition:] dateTime values may be viewed as objects with integer-valued year, month, day, hour and minute properties, a decimal-valued second property, and a boolean timezoned property. Each such object also has one decimal-valued method or computed property, timeOnTimeline, whose value is always a decimal number; the values are dimensioned in seconds, the integer 0 is 0001-01-01T00:00:00 ...
So the format you are looking for is:
2013-09-25T06:00:01
I just pushed a dateTime to NetSuite and it worked.
Import N/format to your script and use one of the date format types:
DATE
DATETIME
DATETIMETZ
var parsedDate = format.parse({
value: '23/12/2010',
type: format.Type.DATE
});
The code looks ok
Are there any restrictions on the date field such that you can't set a date in the past?
Also your serverDt is the same value as the Netsuite help. Did it copy cleanly? What happens if you cut that string and type it directly?
And finally are you sure you have a datetime field and not a date field. If I apply your code to a date field I get the same error.
Little addition on the existing ans.
Error type -
type: "error.SuiteScriptError",
name: "INVALID_FLD_VALUE",
message: "You have entered an Invalid Field Value 2017-07-13T08:21:12.411Z for the following field: custrecord_lastrundate",
The value need to be set as a java script date() object. Even the simple same string of js date will throw error. If you are using moment then below code will work perfectly. Sample for adding next days.
var now = moment();
now.add(1,'days')
fetchRecord.setValue({
fieldId : 'custrecord_lastrundate' ,
value : new Date(now),
ignoreFieldChange : true
});
This is related and the other 2.0 answers are correct for Date/Time fields. However I was trying to set the incident time on the case record which is just the time field, and you have to do something like this:
let incidentTime = new Date(0, 0, 0, incidentDate.getHours(), incidentDate.getMinutes());
Notice - its still a Date object, but the Y, M, D values have to be zeroed for it to work.
Ahh Netsuite - you couldn't just do that behind the scenes yourself..
Please let me know if someone has a different solution.

Handling date format in Pentaho using javascripting

My input excel sheet has field "date" with two different types of values as shown below
2015-03-02 11:06:35
3/2/2015 4:03:53 AM
I am reading them as "string" and performing below logic
var temp = date.getString();
temp = str2date(temp,"dd.MM.yyyy HH:mm:ss");
I get the below error
*Could not apply the given format dd.MM.yyyy HH:mm:ss on the string for 2015-03-02 11:06:35 : Format.parseObject(String) failed*
I tried reading them as "date" , but I got the below error
Unparseable date: " 2015-03-02 11:06:35 "
How can we handle this error?
A couple ideas from the docs. http://wiki.pentaho.com/display/EAI/JavaScript+Values
First try calling getDate() it should be a function associated with the cell in question.
If that doesn't work try calling getNumber() in excel all dates are represented in floating point. The whole number part is days since jan 1 1970 and the fraction part is the percentage of the way through the day. I'm sure if you look around there is a js wrapper around this functionality.
Another idea would be to determine all the numberformat strings. Loop over them catching errors. The one that doesn't throw an error should be the correct one. Or you could write a small regex pattern to better examine the dates coming out.
Finally, I got result. I will explain step by step please follow steps very carefully.
Step 1: Data Grid => I created one field called fail_date i.e String datatype.
Step 2: Modified Java Script Value => I wrote some code like these.Please follow screen shot.
Step 3: Select values => Here i converted date datatype.
Step 4: Modified Java Script Value 2 => Here also i wrote one code.Please follow screen shot.
Step 5: Select values => Finally, I converted require data format.here correct_date field is your required output.
Step 6: Final output screen will be like these.
Step 7: Below screen shot show whole transformation screen.
Hope this helps.
Can you use a library. I've used xdate its really good. And it parses both of these date strings
var xdate = require('xdate');
xdate('2015-03-02 11:06:35').toDate(); // returns a js date object
xdate('3/2/2015 4:03:53 AM').toDate(); // returns another js date object.

Autofilling Form Date and Time in Chrome with Javascript

I'm trying to populate a form on a site with values passed through GET. The two fields I'm having trouble with are input tags that are of type type="date" or type="time". Chrome has this nice feature that gives you a drop down calendar to select a date:
Chrome also does something similar for the Time field. The problem is that it doesn't like javascript that tries to populate those types of form fields. I pass GET information like so:
The reason the date is formatted like this is because that's what the back-end requires (not what I'm working on) and the date comes directly from the back end code.
I have a function that auto-populates document.$_GET as an array with all passed values from GET. I also have date.js included, which allows me to use the Date.parse functionality and some other stuff. I pass it through javascript like this:
if(document.$_GET['time']!=undefined)
document.getElementById('time').value=document.$_GET['time'];
if(document.$_GET['date']!=undefined){
var date = new Date();
date = Date.parse(document.$_GET['date']);
alert(date.toString('MM-dd-yyyy')); // <-- Debugging
document.getElementById('date').value = date.toString('MM-dd-yyyy'); //WHY WON'T YOU WORK!?
}
On Safari I get what I expect to get:
With Chrome I'm left with empty form fields:
I'm stumped and not sure how to remedy this. I need Chrome to autofill similar to how Safari does.
Google Chrome is strict about the format of the Date.
The date works with the following format, YYYY-MM-DD.
The time works with military time. (24h clock)
Here's a sample,
http://jsfiddle.net/vFnxw/2/
$("#date").attr({
value:"2012-09-28"
})
$("#time").attr({
value:"23:59:59"
})
Here are the sources
http://dev.w3.org/html5/markup/input.date.html
http://dev.w3.org/html5/markup/input.time.html

Categories