Custom Javascript auto-submit

Good day, I have a form with a UPC field and once the user scan a connected barcode, he/she is forced to confirm the search result and press the Submit button. I am not a strong javascript user can someone help. the following is the user flow.

SCAN

select the result and press Submit

$(document).on(‘knack-view-render.view_9’, async function (event, view, record) {

const inputFieldKey = ‘field_63’; // The field you want to listen for changes to

$(`#${view.key} #kn-input-${inputFieldKey} select`).on(‘change’, function () {

if ($(this).val()) {

  $(\`#${view.key} button\[type=submit\`).click(); // Auto click the submit button on this view's form

}

});

});

Hi @Michel

what issue you are facing with your current code implementation ?

for button click code part, you can use something like this:

$(‘#’ + view.key + ’ form button[type=submit]').trigger(‘click’);

Thanks for the attention. Actually, to start with I got rid of the connection. As a result, when I scan a barcode in the 1288 field, it auto-submit. But I need to manually move my pointer back to the 1288 filed before I can scan another barcode. I want the script to return the 1288 once the auto-submit commits.

$(document).on(‘knack-view-render.view_1730’, function (event, view) {

const fieldKey = ‘field_1288’; // Votre champ spécifique

// 1. Force Knack / Chosen à ouvrir et donner le focus au champ de recherche

setTimeout(function () {

$(\`#view_1730-${fieldKey}\_chosen\`).trigger('chosen:open');

}, 300);

// 2. Écoute le changement de valeur pour soumettre automatiquement

$(`#view_1730-${fieldKey}`).off(‘change’).on(‘change’, function () {

if ($(this).val()) {

  $(\`#view_1730 button\[type=submit\]\`).click();

}

});

});

try this. I use it on one of my forms. It can work with a connection. If you need that, let me know.

// Autofocus field_1956 on form load
$(document).on(‘knack-view-render.view_1527’, function () {

setTimeout(function () {

$('#view_1527 input[name="field_1956"]').focus();

}, 300);

});