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

Question

Question

Java Script for Field in collection

asked on May 14, 2017 Show version history

Hi,

I am using the following code to hide 'submit' button on a filed that is less than 0.  When I use this for a filed within a collection, it only works on the first row.  Does anyone know how the collection works with multiple rows.  If you can share a script it will be help full.

Thanks in advance.

$(document).ready(function(){
  $(document).on('change', '.UAvariance input', function(){
     var UAvariance = $(".UAvariance input").val();
    var $submit = $('.Submit');
    if (UAvariance < '0'){
      $submit.hide();
    }
    else {$submit.show();}
  });
});

0 0

Replies

replied on May 14, 2017

You can try following scripts:


$(document).on('change', '.UAvariance input', hideSubmitButton);
     
$(document).ready(hideSubmitButton);     

function hideSubmitButton() {
 $(".UAvariance input").each(function(){
  var $submit = $('.Submit');
  if ($(this).val() < '0'){
       $submit.hide();
     }
     else {$submit.show();}
   });
 }

 

0 0
replied on May 15, 2017

Thanks for the reply.  It does the same as the first code.  Whatever filed you edit the last, becomes the primary, therefore if the last edited field is greater than 0 then it shows the submit button.  I need it to work whenever the field in any row is below 0.

 

Thanks!

 

0 0
replied on May 15, 2017 Show version history

Ajanthan, I've done something similar in which I set a counter to zero and then I increment it by 1  if at any point the condition is met. Then all you check is that if the counter is greater than zero, to be true. 

Not tested but something like this.

$(document).on('change', '.UAvariance input', hideSubmitButton);
     
$(document).ready(hideSubmitButton);     

function hideSubmitButton() {

i= 0;

 $(".UAvariance input").each(function(){
  var $submit = $('.Submit');
  if ($(this).val() < '0'){
       // do nothing
     }
     else {
   i++; // increment by 1
}

   });

if (i > 0) { 
$submit.show(); 
} 
else 
{ 
$submit.hide(); 
}

 }

 

0 0
replied on May 15, 2017

Thanks for the script but it does the same as the code above.  let's say if you make a change on the filed in one line to -1 then if you go back to a field on a prior row or after row and change it to 0 or 1 then it shows the submit button.

0 0
replied on May 16, 2017 Show version history

Oh ok. So I thought you wanted to show the button if "at least" one row was zero or more; but it sounds like what you're looking for is to hide the button if "at least" one row is less than zero. Is that right?

If so, then maybe simply change the "Field Type" to "Number" and set the properties of "Min" to zero in the "Range" option. See screenshots.

 

positiveNumbersType.png
positiveNumbers.png
0 0
replied on May 16, 2017

Thanks!

 

that's I have it setup but.  If I put this as a rea-only field it doesn't work.  I am populating the values from a database lookup and I don't want to user to change anything on the field.

0 0
replied on May 16, 2017 Show version history

Ah, that makes sense.

Try this instead. It's similar to my first suggested code, but in reverse. It will flag when there is a textbox with a number less than zero.

  $(document).on('change', '.UAvariance input', hideSubmitButton);
  $(document).on('click', '.form-del-field', hideSubmitButton);
     
$(document).ready(hideSubmitButton);     

function hideSubmitButton() {

var i = 0;

 $(".UAvariance input").each(function(){
  var $submit = $('.Submit');


  if ($(this).val() < '0'){
	i++;
     }
     else {
}


if (i > 0) {
     $submit.hide();
}
else
{
     $submit.show();
}


   });
 }

 

0 0
replied on May 16, 2017

That did the magic.  

Thanks a lot Raul.  

0 0
replied on May 22, 2017

Hi Raul,

 

   Would it be difficult to adjust this code to the input of a yes/no radio button that would only display the Submit button if the selection were yes?

 

Thanks,

Michael

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

Sign in to reply to this post.