You are viewing limited content. For full access, please sign in.

Question

Question

Customizing table with javascript (alert repeated when add new row)

asked on April 10, 2019

I have a field "mobileNo" in a table with a lookup attached to it and a function to run on change.

the function make a validation if tblID column has data come from lookup so it alert user that this number already exist. and it working properly in first row. problem i have when try to adding anew row alert come twice. here is what i tried:

$(document).ready(function(){ 

  $(document).on("lookupcomplete", function () {
    checkNos();  
    $('.tbl1 tbody').on('change', '.mobileNo input', checkNos);      
    function checkNos() {
      $('.tbl1 tbody tr').each(function () {        
        $(this).find('.mobileNo input').each(function () { 
          var tblID = $(this).closest('tr').find('.tblID input').val(); 
          if (tblID !="" && $('#q10 input:checked').val()=="New"){    
            alert('This mobile no already exist!');
            $(this).closest('tr').find('.tblID input').val("")
            $(this).closest('tr').find('.mobileNo input').val("");            
          }else{
          }  
        });   
      });
    }
  });

});
  

here image for table columns 

and this is the lookup rule i did

0 0

Replies

replied on April 11, 2019

Which version of Forms are you running?

0 0
replied on April 12, 2019 Show version history

@████████10.3.1

0 0
replied on April 13, 2019

Solved it. In case anyone else runs into this issue, I add ".one()" after alert syntax.

0 0
replied on June 11, 2019

Hello Mahmoud Gooda

I would like to understand this a bit better.

I believe I have almost exactly the same problem as you.

I am running a super small script on a form which makes two fields read only and sets a value here and here.

Along with the current functionality, I'd like to alert(""); to the end user why the fields are read only.

But I see when alerting, like you said it comes up twice.

$(document).ready(function () {
  
  $('.testTable').on('change', notifyUser);
  
  function notifyUser () {
    $('.testTable tbody tr').each(function () {
      var techSupport = "REV-NET TECHNICAL SUPPORT";
      if($(this).find('.input input').val() == techSupport) {
          alert("No cost for this stock code!");
          console.log("Logging");
      }
    })
  }
});

This is the code I am using. I have played with it a lot and I cannot get it to only either console.log once and/or alert once. 

Every time my field lookups and I select a value from the list (specifically the one specified in code as techSupport variable), it logs and alerts twice.

Any help to this please?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.