cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Setting time portion of date time control

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?

Labels: (2)
Tags (1)
0 Kudos
Reply
14 Replies
Workflow Hero

Re: Custom Javasript not working in New mode

Steven,

In the form date/time control settings, you should be able to Store the ClientID in a javascript variable and use that variable to manipulate via your code rather than using the Element ID's.

Cheers,

Mark

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Javasript not working in New mode

Hi Mark,

Thanks for the suggestion. We know about the JavaScript variable option. We would use it for any other control, but we're unsure how we could use it to set only the hour and minute fields of the date/time control using the variable for the entire control. We want to leave the date portion blank for the user to choose.

See the updated post above which shows a temporary workaround. We'd still like to find something more permanent than using the IDs for the fields though, since they'll change over time if the form is modified.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Javasript not working in New mode

Steve,

Another, less glamorous option would be to have the date fields on the form present as date only fields and add two separate fields for hour and time. you could have these set for a drop-down choice list with pre-populated values (I assume there would not be a huge call for individual minute granularity).

Once the form is submitted you could use a workflow Calculate Date control to combine the original Date and the the two hour/minutes field values.

However, you would first need to extract these hour/minute values out of the Formdata Item property xml and populate into variables (and convert to relevant numbers).

Like I said - less glamorous, but should work!

Regards,

Mark

0 Kudos
Accept as Solution Reply
Not applicable

Re: Setting time portion of date time control

Hi Steve,

 

You are still able to achieve this using the JavaScript variable option. However you would need some tweaking in your javascript to select the Hour Dropdown and Minutes dropdown. Refer to code snippet below:

 

NWF$(document).ready(function(){       var PreTrialHour = 1 + " " + "PM";       var PreTrialMinute = "30";       var date = NWF$("#" + testdate);       var hourddl = date.parent().find("select[id*='DateHours']");       var minddl = date.parent().find("select[id*='DateMinutes']");       hourddl.val(PreTrialHour );       minddl.val(PreTrialMinute); });

 

In this snippet, we basically give our DatePicker a 'testdate' javascript variable name. Then on document ready, we set both the hours dropdown and minutes dropdown to our desired values. Hope this helps you achieve what you want and you would not need to worry of the form mode and also managing the id change.

 

Thanks

Jeremy

Accept as Solution Reply
Workflow Hero

Re: Setting time portion of date time control

Thanks Mark for the reply. Looks like Jeremy offered the most elegant solution

He knew how to access the fields within the date/time control - something I wasn't familiar with.

Thanks everyone!

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Setting time portion of date time control

Thanks so much Jeremy! Just what we were trying to do.

0 Kudos
Accept as Solution Reply
Not applicable

Re: Setting time portion of date time control

Hi Steven,

Glad I could help you on this. Keep the questions coming, you are more than happy to help you guys.

Regards

Jeremy

0 Kudos
Accept as Solution Reply
Not applicable

Re: Setting time portion of date time control

Great Post !

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Setting time portion of date time control

Hi Jeremy,

I have a problem with your suggested solution: It only works every 5 minutes. If the current time is for example 10:07 PM, the "07" is not a legal value according to the minute dropdown's possible values.

How to get around this?

Regards

Leif

0 Kudos
Accept as Solution Reply