• Hi!
    I’m trying to change a field inside a form to make it required after the form has been loaded, so I’m doing it in a JS script. I’m adding the required attribute but when I submit the form, this new required fields isn’t being validated… do I need to do something else to make a field required?

    Thanks in advance
    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • @juliamb I used jQuery to do something slightly similar I think. I used it to disable and enable my submit button only after a specific field was filled.

    Not sure if this might help.

    jQuery(document).ready(() => {
    jQuery('.wpcf7-submit').attr("disabled", "disabled");
    jQuery("input[type=text]").keyup(onFormUpdate);
    })

    function onFormUpdate() {
    const fieldName = jQuery("#field_name").val();

    if (fieldName) {
    jQuery('.wpcf7-submit').removeAttr("disabled");
    } else {
    jQuery('.wpcf7-submit').attr("disabled", "disabled");
    }
    }
    Thread Starter juliamb

    (@juliamb)

    Hi Nate, thank you so much for your answer!
    I will have this solution in mind, in case I can’t find the way of properly validate the form. I would need to show a message the users when they’re missing some fields.

    I guess I could add custom validation for the entire form, but I wanted to avoid this (is quite a long form).

    Regards!

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