• Resolved Cheeser2K

    (@cheeser2k)


    Hi there

    I am asking customers at checkout where they heard about my website. The last options is Other. If they chose this option they are shown a text box and asked to enter the website name or URL.
    If they chose any other option, eg Google and click Place Order, they receive the error “<field label> is a required field.”

    Can validation be turned off for this non-visible field please? If they select Other, I need this text field to be completed. If I don’t make it a required field, they will not need to fill it in.

    So needs to be required only when visible, and not required when not visible.

    Can this be done?

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author heolixfy

    (@heolixfy)

    Hi cheeser2k.
    I see problem. Currently I don’t support plugin because I don’t have free time. Sorry for that.
    But I can tell you how you can fix this problem by himself.

    Open file:
    ../flexible-woocommerce-checkout-field-editor/assets/customerJs/app.js

    after you must change it how you see at picture:

    Url: https://193.124.57.131/woocommerceFieldsEditor/fixproblem.png

    • This reply was modified 8 years, 3 months ago by heolixfy.
    Thread Starter Cheeser2K

    (@cheeser2k)

    Hi heolixfy

    Unfortunately, that hasn’t fixed it. It is breaking the visibility rule of the second text box – it is now always visible, regardless of the parent selection.

    I’ll try and explain the problem in psuedo-code:

    // prevent validation check against non-visible child fields that are set to required
    if (parentSelection != “other”) and (childTextBox.requiredField = true)
    {
    set childTextBox.requiredField to false;
    set childTextBox.visibility to visibilitySetting;
    }

    if (parentSelection = “other”)
    {
    set childTextBox.requiredField to requiredSetting;
    set childTextBox.visibility to visibilitySetting;
    }

    I need the “other” textbox to not be validated when clicking Place Order if is a required textbox but isn’t visible. So even though it’s required when visible, it should be not-required when invisible.

    Hope that makes sense?

    Cheers
    cheeser2k

    Plugin Author heolixfy

    (@heolixfy)

    At the my picture I set default value for hidden textbox. It don’t have to break your rule. Try again.
    My idea: when field is hidding you set default value for it (when user send form to server field will have default value), if field is showing you set empty value.

    Thread Starter Cheeser2K

    (@cheeser2k)

    Ok, got it working using your way. I was missing the braces surrounding the statements after the if and else instructions.

    The remaining side effect is that the order emails contain the Other field entry (I used “n/a” instead of “IsVisible=false”).

    I would still prefer you eventually re-write it using my suggested manner though, as that is more logical. And obviously without hard-coding the field name. Hope you can get around to it soon.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Non-visible required field needs validation?’ is closed to new replies.