I've got a weird one. I have a form on Cloud that is setup with two single line fields, one for first name, one for last name, a checklist with fifteen options, then a collection of fifteen single line fields. I have Javascript that will populate one of the single line field with a value if the corresponding checkbox is checked, and code to clear it if it's unchecked. This works fine if I do things in order top to bottom, i.e. type in the name, then click out and THEN select the checkbox. HOWEVER if I select some checkbox items (or if the fields are populated by the workflow that starts the process, doesn't matter which, as long as the fields have values) and then type anything into the first name or last name field, losing focus on the single line fields clears the values in my collection of single line fields. Nothing in the code I wrote is doing this (I have tested it a fair amount and got two other sets of eyes on it). The weirdest part is when I recreated the situation on my on-prem forms environment, this does not occur. Here's a video of it in action in case my explanation is unclear: https://www.screencast.com/t/3IicVxAZ
Any thoughts? I submitted a case and am waiting for a solution, and I think I can work around this to an extent but it isn't the most user friendly solution so I'd like to figure out how to fix this.
Here's my code (with some things redacted for client privacy):
$(document).ready(function () { $('.top').removeClass('label-left'); //put checkbox label on top of field rather than left }); $(document).on("change", '#q1 input[type="checkbox"]', function() { if (this !== undefined && this.id !== undefined) populateFields('input[id="' + this.id + '"]'); }); function populateFields(checkboxID) { console.log(checkboxID); if ($(checkboxID).is(':checked')) { switch (checkboxID) { case 'input[id="Field1-0"]': $('#q27 input').val('redacted'); $('#q27 input').change(); break; case 'input[id="Field1-1"]': $('#q28 input').val('redacted'); break; case 'input[id="Field1-2"]': $('#q29 input').val('redacted'); break; case 'input[id="Field1-3"]': $('#q30 input').val('redacted'); break; case 'input[id="Field1-4"]': $('#q31 input').val('Income verification'); break; case 'input[id="Field1-5"]': $('#q32 input').val('redacted'); break; case 'input[id="Field1-6"]': $('#q33 input').val('redacted'); break; case 'input[id="Field1-7"]': $('#q34 input').val('redacted'); break; case 'input[id="Field1-8"]': $('#q35 input').val('redacted'); break; case 'input[id="Field1-9"]': $('#q36 input').val('redacted'); break; case 'input[id="Field1-10"]': $('#q37 input').val('redacted'); break; case 'input[id="Field1-11"]': $('#q38 input').val('redacted'); break; case 'input[id="Field1-12"]': $('#q39 input').val('redacted'); break; case 'input[id="Field1-13"]': $('#q40 input').val('redacted'); break; case 'input[id="Field1-14"]': $('#q41 input').val('redacted'); break; } } else if (!$(checkboxID).is(':checked')) { switch (checkboxID) { case 'input[id="Field1-0"]': $('#q27 input').val(''); break; case 'input[id="Field1-1"]': $('#q28 input').val(''); break; case 'input[id="Field1-2"]': $('#q29 input').val(''); break; case 'input[id="Field1-3"]': $('#q30 input').val(''); break; case 'input[id="Field1-4"]': $('#q31 input').val(''); break; case 'input[id="Field1-5"]': $('#q32 input').val(''); break; case 'input[id="Field1-6"]': $('#q33 input').val(''); break; case 'input[id="Field1-7"]': $('#q34 input').val(''); break; case 'input[id="Field1-8"]': $('#q35 input').val(''); break; case 'input[id="Field1-9"]': $('#q36 input').val(''); break; case 'input[id="Field1-10"]': $('#q37 input').val(''); break; case 'input[id="Field1-11"]': $('#q38 input').val(''); break; case 'input[id="Field1-12"]': $('#q39 input').val(''); break; case 'input[id="Field1-13"]': $('#q40 input').val(''); break; case 'input[id="Field1-14"]': $('#q41 input').val(''); break; } } }