91π
This must be happening with angular 1.3+. 1.3+ on wards ng-model for date/time input needs to be a valid date object, string representation of date is no longer allowed. You need to convert string to date object ($scope.created_time = new Date(dateString)
) and bind it to the ng-model. If you follow the error link it has a clear description about the error and how to resolve it.
All date-related inputs like require the model to be a Date object. If the model is something else, this error will be thrown. Angular does not set validation errors on the in this case as those errors are shown to the user, but the erroneous state was caused by incorrect application logic and not by the user.
35π
If you get your data from a REST Service, you can simply convert your fields to Date.
$http.get(url).success(function(data){
$scope.data = data; // get row data
$scope.data.mydatefield = new Date($scope.data.mydatefield); // convert filed to date
});
- [Django]-How to get the current URL within a Django template?
- [Django]-Django 1.3.1 compilemessages. Error: sh: msgfmt: command not found
- [Django]-Is Django for the frontend or backend?
21π
Create a simple directive that converts the model value:
HTML:
<input date-input type="time" ng-model="created_time">
Directive:
app.directive('dateInput', function(){
return {
restrict : 'A',
scope : {
ngModel : '='
},
link: function (scope) {
if (scope.ngModel) scope.ngModel = new Date(scope.ngModel);
}
}
});
- [Django]-What is the equivalent of "none" in django templates?
- [Django]-Django Forms and Bootstrap β CSS classes and <divs>
- [Django]-How do I create a slug in Django?
12π
In addition to PSLβs answer.
This is how to override angular 1.3+ requirements to be a Date object.
<input type="date" ng-model="book.date" date-format/>
app.directive('dateFormat', function() {
return {
require: 'ngModel',
link: function(scope, element, attr, ngModelCtrl) {
//Angular 1.3 insert a formater that force to set model to date object, otherwise throw exception.
//Reset default angular formatters/parsers
ngModelCtrl.$formatters.length = 0;
ngModelCtrl.$parsers.length = 0;
}
};
});
It can be used with AngularFire $firebaseObject and works fine with $bindTo 3-way binding. No need to extend $firebaseObject service. It works in Ionic/cordova applications.
Based on this answer
- [Django]-Can you perform multi-threaded tasks within Django?
- [Django]-Logging in Django and gunicorn
- [Django]-Models.py getting huge, what is the best way to break it up?
1π
if date get reduced by 1 day, use this code,
new Date(moment.utc(value).format('l LT'))
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-Filter by property
- [Django]-How do I make many-to-many field optional in Django?
1π
In a way similar to cs1707 answer, I had to create a directive but doing a part by part string to time conversion. I added it as an answer for those who want fast to copy code.
Add this directive:
app.directive("formatTime", function(){
return {
require: 'ngModel',
link: function(scope, elem, attr, modelCtrl) {
modelCtrl.$formatters.push(function(modelValue){
var string=modelValue;
var date=new Date();
var time=string.split(':');
date.setHours(+time[0]);
date.setMinutes(time[1]);
date.setSeconds(time[2]);
return date;
})
}
}
})
And format-time
to your HTML input tag:
<input type="time" data-ng-model="mytime" format-time>
- [Django]-Django-Admin: CharField as TextArea
- [Django]-Get SQL query count during a Django shell session
- [Django]-How to get a favicon to show up in my django app?
0π
Problem Actually this is date format issue, I have resolved this issue by using this piece of code.
Solution: Below piece of code will solve this issue:
var options = {
weekday: "long", year: "numeric", month: "short",
day: "numeric", hour: "2-digit", minute: "2-digit"
};
$scope.created_time = $scope.created_time.toLocaleTimeString("en-us", options);
where en-us format = βFridayβ, βFebβ β1β, β2013β β06β:β00β βAMβ, hope this will help others to solve issue, i was facing such error and resolved with this.
- [Django]-Django: remove a filter condition from a queryset
- [Django]-How to deal with "SubfieldBase has been deprecated. Use Field.from_db_value instead."
- [Django]-How to access the local Django webserver from outside world
0π
I had this error and i directly used the object: I am posting the solution witch i carried out:
1:$userData.dob=new Date(userData.dob);
2:$scope.edit.userdob=userData.dob;
before 1 i faced above error then i directly created the object and assigned it to the edit scope and the problem got resolved.
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)
- [Django]-ReactJS with Django β real usage
-2π
If you need to update all dates in Array with Objects
var data = [
{ id: "1" , birthday: "2016-01-20T11:24:20.882Z"},
{ id: "2" , birthday: "2016-01-20T11:24:20.882Z"},
{ id: "3" , birthday: "2016-01-20T11:24:20.882Z"},
];
function convertDataStingToObject (data) {
for(var i=0; i < data.length; i++ ){
console.log('string: ' + data[i].birthday);
data[i].birthday = new Date(data[i].birthday);
console.log('updated: ' + data[i].birthday);
console.log(typeof(data[i].birthday));
}
return data;
}
convertDataStingToObject(data);
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
- [Django]-Django admin file upload with current model id
- [Django]-How to merge consecutive database migrations in django 1.9+?