claudiaurbanski
Process Pupil

Reset lookup in repeating section based on checkbox

Jump to solution

The following js is working only for the first row of the repeating section, I need it to work for all repeating section rows.Please help.

 

When box is checked, lookup resets to "Please select a value"

 

Checkbox var-cidContractor

Dropdown var- cidTraining

 


NWF$(document).ready(function(){
   NWF$('#'+cidContractor).change(function() {
      if(NWF$('#'+ cidContractor).prop("checked")) {         NWF$('#'+cidTraining).val("");NWF$('#'+cidTraining).siblings('select.nf-client-control').val('**SelectValue**');      }   })});

0 Kudos
Reply
5 Replies
MegaJerk
Automation Master
Automation Master

Re: Reset lookup in repeating section based on checkbox

Jump to solution

are both the Checkbox and the Dropdown in the Repeating Section, or is the Checkbox outside of it? 

If you're trying to target Controls inside of a Repeating Section (Row), then you need to use a classname (less complicated) or a Control Name (a little more complicated but not by much) to target them because ID values must be unique! Setting an ID variable for a Control in a repeating section will only return one result because of this! 

0 Kudos
Reply
claudiaurbanski
Process Pupil

Re: Reset lookup in repeating section based on checkbox

Jump to solution
@MegaJerk Thank you for your reply, the checkbox and the dropdown are both inside the repeating section.
0 Kudos
Reply
MegaJerk
Automation Master
Automation Master

Re: Reset lookup in repeating section based on checkbox

Jump to solution

Made a little test form. I have a Repeating Section with two Controls.

 

One is a Yes / No checkbox named: control_Checkbox_LookupReset

 

One is a Lookup Control named: control_Lookup_Fruits

MegaJerk_0-1613073272309.png

 

What I mean by "name" is that the Control Name has been set in the properties, just to be clear: 

MegaJerk_1-1613073304005.png

 

Now that we have our controls, we can use the code you have and just give it a little change:

NWF$(document).ready(function() {
  NWF$(".nf-filler-control[data-controlname='control_Checkbox_LookupReset']:visible").change(function(event) {
    var checkbox = NWF$(event.target);
    var targetIsChecked = checkbox.prop("checked");
    var targetLookup = checkbox.closest(".nf-filler-control").siblings("[data-controlname='control_Lookup_Fruits']");

    if (targetIsChecked) {
      targetLookup.find("select.nf-client-control").prop("selectedIndex", 0).trigger("change");
    }
  });
});

 

In the code above I'm find the controls by way of their Control Name, first setting up an event handler when our checkbox control, "control_Checkbox_LookupReset" is changed, and then I'm handling it with a function that:

 

  1. Sets a variable named "checkbox" to equal the Checkbox Control
  2. Sets a variable named "targetIsChecked" to checkbox's value
  3. Sets a variable named "targetLookup" to be that of our sibling Lookup Control

We then use a simple conditional to see if checkbox IS checked, and if it is, then we dig down into our Lookup Control to find that actual Select element that we (a user) would normally interact with, set it's value to 0 (which is the default index of the "Please Select A Value" 'value'), and indicate that we've made a change using the ".trigger("change")" event trigger (which should fire off any Formatting / Validation Rules that may be tied to this control. 

In action, all this does is clear the Lookup Control when the box above it is checked:

MegaJerk_4-1613074695188.png

 

MegaJerk_3-1613074683345.png

 

Hope this helps to get you there. 

 

 

 

 

View solution in original post

0 Kudos
Reply
claudiaurbanski
Process Pupil

Re: Reset lookup in repeating section based on checkbox

Jump to solution

@MegaJerk Thank you!!!!!!!!!!!!!!!!!! It worked like a charm. I really appreciate your detailed response. Thank a lot! : )

0 Kudos
Reply
MegaJerk
Automation Master
Automation Master

Re: Reset lookup in repeating section based on checkbox

Jump to solution

Glad it worked! Enjoy your new form! 

0 Kudos
Reply