A newer version of this content is available on ReWorkflow ReSource.
This page is a dumping ground for little JavaScript tidbits that Slaters may find helpful. If you can suggest an improvement, please do!
Unhide all hidden elements on a form (useful for debugging):
$("[id^='form_page'], [id^='form_question']").show();
Wait for the page to load:
// Wait for the page to finish loading $(function () { // Do stuff here });
Select Slate form element:
$("form[id^='form_'][id$='_container']");
Get the form/event's GUID - can be put in a Calculation Formula and become an email merge field:
$("form[id^='form_'] input[name=id]").val();
Select city field of permanent address block:
$("[data-export='sys:permanent'] [name$='_city']");
Get a form field's value:
Form.getValue('sys:field:my_field');
Get sys:email's value (this one is special):
$("[data-export='sys:email'] input").val();
Control a hidden related event selector via checkboxes:
//Find hidden related event selector options var $audition_checkbox = $('[data-export="related_event"] input[value *= "April 23"]'); var $workshop_checkbox = $('[data-export="related_event"] input[value *= "April 22"]'); //Attach change handler to workshop event question. Select related events based on prompt value matches $('[data-export="event"] input').change(function (event) { if (form.getValueArray('event').includes('audition')) { $audition_checkbox.prop('checked', true); } else { $audition_checkbox.prop('checked', false); } if (form.getValueArray('event').includes('workshop')) { $workshop_checkbox.prop('checked', true); } else { $workshop_checkbox.prop('checked', false); } });
Sum up the value of items in a checkbox question. Note the use of _list to get an array instead of a string in the calculation formula engine. Source
var total = 0; $.each(@fieldkey_list, function(){ total += parseInt(this); }); total;