AmanG
Nintex Newbie

Javascript issue in repeating section

Jump to solution

In Nintex form repeating section, i want current date in textbox on click of checkbox button.

As recommended in other blogs, i used class and not id. But now issue is when i click on add new row and click on checkbox, it changes date for all the previous textboxes as well because of same class getting applied to all the textboxes. Below is my code for it.  RS1 is class name for checkbox inside repeating section and RS1NAME is class name for textbox inside same repeating section.

 

Please suggest.

 

NWF$(".RS1 input[type='checkbox']").change(function(){
if(NWF$(this).prop('checked')){
var today = new Date().toLocaleDateString();
NWF$(".RS1NAME").val(today);
});

0 Kudos
Reply
2 Replies
MegaJerk
Automation Master
Automation Master

Re: Javascript issue in repeating section

Jump to solution

Looks like you just need to add some 'context' to what it is you're trying to do. 

Targeting the class ".RS1NAME" is going to return ALL of the date fields because you're not being specific as to which one you'd like to get. 

 

Using the following code, it should work. Please note that I've made some changes because I could not get your code to work on my side (even just to add a date to anything):

 

NWF$(".RS1 input[type='checkbox']").change(function() {
  if (NWF$(this).prop('checked')) {
    var context = (NWF$(this).closest(".nf-repeater-row").length > 0
      ? NWF$(this).closest(".nf-repeater-row")
      : NWF$(document)
    );    
    var today = new Date().toLocaleDateString();
    context.find(".RS1NAME .nf-associated-control").val(today);
  }
});

 

Now instead getting ALL controls with the class "RS1NAME" it will only target the controls within the context of the current control that is firing the event. 

View solution in original post

Reply
AmanG
Nintex Newbie

Re: Javascript issue in repeating section

Jump to solution

Thank you Meg

0 Kudos
Reply