We're trying to set the default hour and minute values for some date/time controls on a Nintex form. We don't want to set the date portion of the control or we'd just use the SharePoint column default value option or the JavaScript variable option in the Nintex form settings.
Â
Temporary Workaround
Use the correct ID sets for the mode the form is in. The IDs can be different for the same field when the form is in New/Edit/Display. Thanks to Chit and this post for the idea about testing form mode: How can I get the form mode (New, Edit, Display) using jquery (NFW$)?
Â
var isNewMode = document.location.pathname.indexOf("/NewForm.aspx") > -1; var isEditMode = document.location.pathname.indexOf("/EditForm.aspx") > -1;Â if (isNewMode) { Â /*set time values*/ var PreTrialHour = 1 + " " + "PM"; var PreTrialMinute ="30";Â /*populate the time fields*/Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â document.getElementById('ctl00_ctl43_g_55233958_e3e3_4fc0_8fd8_8cf8652d8648_ctl00_ListForm2_formFiller_FormView_ctl86_DateHours').value=PreTrialHour;Â Â document.getElementById('ctl00_ctl43_g_55233958_e3e3_4fc0_8fd8_8cf8652d8648_ctl00_ListForm2_formFiller_FormView_ctl86_DateMinutes').value=PreTrialMinute;Â Â Â }Â if (isEditMode) { Â /*set time values*/ var PreTrialHour = 1 + " " + "PM"; var PreTrialMinute ="30";Â /*populate the time fields*/Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â document.getElementById('ctl00_ctl43_g_4c336315_ff71_484c_844e_96f33d3e5580_ctl00_ListForm2_formFiller_FormView_ctl86_DateHours').value=PreTrialHour;Â Â document.getElementById('ctl00_ctl43_g_4c336315_ff71_484c_844e_96f33d3e5580_ctl00_ListForm2_formFiller_FormView_ctl86_DateMinutes').value=PreTrialMinute;Â Â }
Â
Â
Anyone have a better way to set the hour and minute fields that doesn't rely on the ID value of the individual fields which can change over time?