A space will pass required field validation

Support General A space will pass required field validationResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35604
    Stephen C.Stephen C.
    Participant

    A slight problem with required fields: Users can bypass required text fields simply by entering a space in the box. If you have a required field, a space (or spaces) as the only entry in that field isn't what you want, because that's basically the same as an empty field. So, if would be helpful if the validation code could be updated to trim spaces before checking for empty fields.

    #35615
    Long NguyenLong Nguyen
    Moderator

    Hi Stephen,

    You can create a custom function to check the field value through remote validation. Refer to the documentation https://docs.metabox.io/validation/#using-code-1
    and this topic https://support.metabox.io/topic/remote-validation-example/#post-22957

    #35624
    Stephen C.Stephen C.
    Participant

    I want to use the javascript validation first, before submitting anything to the server. I fixed the issue by unminifying validation.min.js and adding a bit of code immediately after this.$form.on("submit", function () { to trim the values before the validator is called. Now it works as it really should.

    #35637
    Long NguyenLong Nguyen
    Moderator

    Hi Stephen,

    The remote validation is the Javascript with the callback PHP function like AJAX. It's not encouraged to modify the plugin source code directly, it will be overridden when updating the new version of the plugin.

    #35647
    Stephen C.Stephen C.
    Participant

    I already have to modify the source code before updating each time. I have had to make several changes to fix issues with MB to make it work as desired on my site, like adding a parameter to allow me to set the autocomplete attribute (autocomplete="off") on the frontend submission and user profile forms to prevent browser caching of form field values when needed, setting an actual form id instead of just using the a comma separated list of meta box ids as the form id for frontend submission forms, code that allows for reinitializing image fields so forms can be completely reset to their original state without having to reload them (useful when displaying a form in a modal, such as an avatar select/upload, and the user cancels the modal instead of submitting), modifying media.js to use a different trigger to change images instead of using .rwmb-image-overlay so that a button can be used in addition to the overlay (users often don't get that clicking the overlay will allow them to change images), and a few other things.

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