- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:35 AM
Hi ,
I need to set today's date as default date for input ( i can be modified by user), in widget.
Please suggest.
<div>
<input type="date" id="valid_for" name="valid_for" ng-model="data.valid_for">
</div>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 05:45 AM
According to the AngularJS docs : https://docs.angularjs.org/api/ng/input/input%5Bdate%5D , the date must be in the form of a Date object (javascript date object).
If you're setting it with a ServiceNow date object (GlideDate), it won't work because it's not the same as a regular javascript date object.
In this case it can be set from the client side using "new Date()";
<input class="form-control" type="date" id="valid_for" name="valid_for" ng-model="c.valid_for">
Client controller
api.controller=function() {
/* widget controller */
var c = this;
c.valid_for = new Date();
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 06:25 AM - edited 08-13-2024 06:35 AM
Yes. Your ngModel is still using the "data" object which is from the server side.
Change ng-model="data.valid_for" to ng-model="c.valid_for"
Edit:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 08:24 AM
Thanks @ChrisBurks - For providing solution.
Can we hardcode any other date( in place of today's date , e.g. 31-DEC-2055)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 09:02 AM
Yes. The Date object can take an argument.
new Date('31-DEC-2005');