A space will pass required field validation
- This topic has 4 replies, 2 voices, and was last updated 3 years, 7 months ago by
Stephen C..
-
AuthorPosts
-
April 13, 2022 at 7:16 AM #35604
Stephen C.
ParticipantA 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.
April 13, 2022 at 9:31 PM #35615Long Nguyen
ModeratorHi 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-22957April 14, 2022 at 4:21 AM #35624Stephen C.
ParticipantI 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.
April 14, 2022 at 9:07 PM #35637Long Nguyen
ModeratorHi 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.
April 15, 2022 at 5:12 AM #35647Stephen C.
ParticipantI 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.
-
AuthorPosts
- You must be logged in to reply to this topic.