Hi,
I have a plugin that extend the Create Issue operation. I need to programmatically, in javascript, set a date field to a value based on complex rules.
But when I try to use eg. AJS.$('#customfieldxxx').val(dateObject), it obviously doesn't work since it has to respect the pattern (dd/MMM/yy).
How can I set a date object to a date field?
Thanks in advance!
Community moderators have prevented the ability to post new answers.
First, add jira.webresources:jquery-livestamp as a dependency in your plugin.
Then you should have available moment.js library and JIRA.translateSimpleDateFormat function. The latter will translate JIRA's date/time format into what moment accepts. Then you can use it like this:
var m = moment(new Date()); var dateString = m.format(JIRA.translateSimpleDateFormat(AJS.Meta.get("date-dmy"))); $('#datePicker').val(dateString);
Check out moment.js' website for info on how to use it.
AJS.Meta takes value of the meta tag in the document with name attribute equal to ajs-date-dmy. Check out the page source for more such attributes (including different variants of the date format).
This works like a charm :) Thank you very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome solution. Liked it so much that I ended up posting about this here. At least for my own benefit ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there official documentation we can read for the JIRA and AJS global variable?
I found partial documentation of the AJS global variable but I don't see everything about it here: https://docs.atlassian.com/aui/latest/docs/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am wondering why you use the 'date-dmy' configuration, JIRA has a configured property for the date input fields called jira.date.picker.java.format. Is there any way to get this property from/through AJS?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
something like you have to try with javascript
var now = new Date(); var day = ("0" + now.getDate()).slice(-2); var month = ("0" + (now.getMonth() + 1)).slice(-2); var today = now.getFullYear()+"-"+(month)+"-"+(day) ; $('#datePicker').val(today);
check this
http://stackoverflow.com/questions/12346381/set-date-in-input-type-date
http://stackoverflow.com/questions/9921944/set-initial-value-in-datepicker-with-jquery
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah but I would like to comply to the date format globally defined in Jira (not constructing the string myself, but using an api that hide the complexity from my side by just passing the date object).
That should be available somewhere, but I don't know where :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.