Javascript On Repeating Section

  • 18 October 2017
  • 6 replies
  • 7 views

Badge +2

Hi,

i am new to JavaScript and am trying to find a way to do a select all on a Choice Control that is in a repeating section.

I have it working for only the first row if you add another row the button doesn't work for the second row. Is there a way to have a select all for all the choice buttons in the repeating section not just the first row?

Here is my javascript code that works for the first row

function selectAll()
{NWF$("#" + Site).find(":checkbox[value='ALB']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='ECH']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='OCA']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='HDQ']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='AUR']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='MTC']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='HAM']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='WCW']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='BAR']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='CLE']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='HER']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='BRN']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='DEC']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='LVC']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='CHA']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='DEN']").attr("checked",true);
NWF$("#" + Site).find(":checkbox[value='MID']").attr("checked",true);
}


6 replies

Userlevel 5
Badge +14

I see you have 'Select All' out of repeating section (row).

so the question, how should it behave if there are multiple row already created in repeating section? should it select all the choice options on all the rows?

if not, how do you identify which row should it work for?

Badge +2

I think that's my issue.. When I built (Copied from other posts) the function I didn't think about the repeating section until the user complained lol.

I would like the select all button hit one time and select all the choice options in all rows

Userlevel 5
Badge +14

ok, then I think following might help you

function selectAll() {
  NWF$('.rsClass .nf-repeater-row:not(.nf-repeater-row-hidden) .SiteChoiceClass input:checkbox').prop("checked",true);
}‍‍‍

rsClass is CSS class configured for repeating section

SiteChoiceClass is CSS class configured for 'Site' choice

‌ 

Badge +2

WOW!!! Thanks that is better than I could have hoped and a lot simpler...

Badge +9

How can I get the following code (adapted from another thread) to work in subsequent rows in a repeating section?

NWF$(document).ready(function () {

NWF$("#" + ResponsibleBU).change(function () {
   NWF$("#" + ResponsibleBUEmailAddress).change();
});

NWF$("#" + ResponsibleBUEmailAddress).change(function () {

var ResponsibleBUEmailAddressId = ResponsibleBUEmailAddress.substring(0, ResponsibleBUEmailAddress.length - 4);
var len = NWF$("#" + ResponsibleBUEmailAddressId).find("option").length;
if (len >= 2) {
   return delay(500).then(function () {
   NWF$("#" + ResponsibleBUEmailAddressId).prop('selectedIndex', 1).change();
   NWF$("input#" + ResponsibleBUEmailAddressId).val(NWF$("#" + ResponsibleBUEmailAddressId).find("option")[1]);
});
}
else {

   while (i < 10 && len == 1) {
   i++;
   return delay(500).then(function () {
        len = NWF$("#" + ResponsibleBUEmailAddressId).find("option").length;
        if (len >= 2) {
            NWF$("#" + ResponsibleBUEmailAddressId).prop('selectedIndex', 1).change();
            NWF$("input#" + ResponsibleBUEmailAddressId).val(NWF$("#" + ResponsibleBUEmailAddressId).find("option")[1]);
        }
    });
}
}});
function delay(t) {
       return new Promise(function (resolve) {
            setTimeout(resolve, t)
       }); 
  }});

Userlevel 5
Badge +14

Hi ‌,

this code is designed for lookup controls.

this thread deals with choice controls instead.

from your other recent posts I've feeling that you're looking for a solution for choices as well. I'd suggest to start your own new question and describe what exactly you need and what's your setup.

Reply