- 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 04:38 AM
I think you can use AngularJS expression like this
otherwise I think you can leverage the server side scripts using - GlideDate
<div>
<input type="date" id="valid_for" name="valid_for" ng-model="data.valid_for"
ng-init="data.valid_for = (new Date()).toISOString().split('T')[0]">
</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2024 05:04 AM
hi @imajad
Thanks for response. But it did not work.
- 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 05:55 AM