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

Question

Question

make a field required when another field is not empty

asked on November 2, 2015 Show version history

On the following form, I would like to make the qty for each line a required field only when there is something typed in the Description field for that line.

 

 

0 0

Answer

APPROVED ANSWER
replied on November 2, 2015

You can use javascript like below:

$(document).ready(function () {
  
  $('.cf-table-block').on('blur', 'input', checkdesc);
  
  function checkdesc() {
    $('.cf-table-block tbody tr').each(function () {
      if ($(this).find('.description input').val() != "") {
        $(this).find('.quantity input').attr('required', true);
      } else {
        $(this).find('.quantity input').attr('required', false);
      }
    });
  }

});

For the description column, give it the CSS class name, description. For the Qty column, give it the CSS class name quantity.

1 0

Replies

replied on November 3, 2015

Thank you...Worked perfect.

 

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

Sign in to reply to this post.