• Resolved pocosryanvirteom

    (@pocosryanvirteom)


    Hi I am in the process of rebuilding an already made form. We used Nex-Forms to start, and have a license from Nex-Forms. I know there is validation built in to each field. We have a field which should take zip codes. However, I only want the user to be able to succeed if they input a valid zip code from an array, any other zip code I want to display an error. I have generated some javascript which should be able to accomplish this. I have removed the zip codes that I have, while testing, and have not modified the next button ID to reflect the actual form from testing.

    document.addEventListener('DOMContentLoaded', function () {
    // Allowed zip codes
    var allowedZipCodes = [
    '00000'
    ];

    var zipCodeField = document.getElementById('nFormZipCode');
    var nextButton = document.getElementById('nextButtonId');

    if (zipCodeField && nextButton) {
    zipCodeField.addEventListener('input', function () {
    var zipCode = zipCodeField.value.trim();
    if (allowedZipCodes.includes(zipCode)) {
    zipCodeField.setCustomValidity(''); // Valid input
    nextButton.disabled = false; // Enable Next button
    } else {
    zipCodeField.setCustomValidity('Invalid zip code.'); // Generic invalid input message
    nextButton.disabled = true; // Disable Next button
    }
    });

    // Initially disable the next button
    nextButton.disabled = true;
    }
    });

    I can’t find a place to insert this without the form validation at form submit. Is there a way to have validation on the “next” button?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Basix

    (@webaways)

    Hi,

    You can use your theme’s custom CSS options and then you need to trigger your custom code from the click event on the next button, for example:

    jQuery(document).on(‘click’, ‘div.ui-nex-forms-container .nex-step’, function(e){
    e.preventDefault();

    /* Your code here */

    });

    For future support please use our official support system at https://basix.ticksy.com

    Thank you

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.