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

Question

Question

Enable Focus to the next field within a Collection

asked on August 22, 2024 Show version history

Hello all.  I have a form using the script below.  The Label Part Scan field is meant to accept value from a scanner.  What I am struggling to get working is to set the Focus to the Job# field in the same row as the Label Part Scan field that just changed.

I was able to get it working outside a Collection, but inside the collection, the cursor stays at the Label part Scan field after the scaned value and does NOT move to the Job# field.

 

$(document).ready(function() {
//  debugger;
  $('li[attr="Collection"]').on("change", 'li[attr="Scan"] input', compare2Table);
  });
                  
function compare2Table() {
  let barcode = this.value;
  let el_row = $(this).closest('ul');
  let el_part = $(el_row).find('li[attr="Part"] input');
  let el_posative = $(el_row).find('li.posative');
  let el_negative = $(el_row).find('li.negative');
  let el_matched = $(el_row).find('li[attr="Matched"] input'); // Find the matched field
  
  
  if (el_part.length > 0) {
    if (barcode && barcode === el_part[0].value) {
      console.log('Match');
//      $(el_posative).removeClass('hidden');
//      $(el_negative).addClass('hidden');
      $(el_row).css('background-color', '#AFE1AF');
      $(el_matched).val(1);
    }
    else if (barcode && barcode != el_part[0].value) {
      console.log('No match');
//      $(el_posative).addClass('hidden');
//      $(el_negative).removeClass('hidden');
      $(el_row).css('background-color', 'red');
      $(el_matched).val(0);
    }
    else {
      console.log('barcode is empty');
//      $(el_posative).addClass('hidden');
//      $(el_negative).addClass('hidden');
      $(el_row).css('background-color', '');
      $(el_matched).val(0);
    }
  }

};

 

0 0

Replies

replied on August 22, 2024

It's hard to tell what variables are which fields on your form, but whenever you have validated the inputs and are ready to change the focus, you can use:

const $jobId = $(el_row).find('li.JobNumber input');
$jobId.focus();

Make sure to update the selector within .find to pulll the right input, and using el_row as the parent will ensure you stay within the same row.

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

Sign in to reply to this post.