Owen Leonard
efeed28f7f
This patch improves the way we handle required fields in the patron entry/update form in the OPAC. Instead of doing multiple checks for each field using mandatory.defined(), the template now loops over a list of fields and sets a "required" variable for any which are required. Then, for each form field, the "required" variable is used to set classes on labels, input fields, and the "required" text hints. The class on form fields acts as a hook for the jQuery validator plugin. The class on the text hints allows us to hide the text hint using CSS, eliminating the necessity of using a template conditional. The patch also adds the missing validator-strings include which enables translation of the jQuery validator plugin's validation error messages. To test, apply the patch and rebuild the OPAC CSS (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client). - Go to Administration -> System preferences and enable PatronSelfRegistration. - Select multiple fields to be required using the PatronSelfRegistrationBorrowerMandatoryField preference. - In the OPAC, start the process of registering for an account. - The fields you designated as mandatory should each have a "Required" label under them. - Try to submit the form without entering any data. The required fields should now be highlighted in red and have another label, "This field is required." - Fill in the required fields and submit the form. It should submit correctly. - Modify the PatronSelfRegistrationBorrowerMandatoryField preference and select all fields as mandatory. Confirm that all fields in the patron entry form work correctly. - Test that form validation works correctly when modifying a logged-in patron's existing account. Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
24 lines
1.3 KiB
PHP
24 lines
1.3 KiB
PHP
<!-- validator-strings.inc -->
|
|
<script>
|
|
$(document).ready(function(){
|
|
jQuery.extend(jQuery.validator.messages, {
|
|
required: _("This field is required."),
|
|
remote: _("Please fix this field."),
|
|
email: _("Please enter a valid email address."),
|
|
url: _("Please enter a valid URL."),
|
|
date: _("Please enter a valid date."),
|
|
dateISO: _("Please enter a valid date (ISO)."),
|
|
number: _("Please enter a valid number."),
|
|
digits: _("Please enter only digits."),
|
|
equalTo: _("Please enter the same value again."),
|
|
maxlength: $.validator.format(_("Please enter no more than {0} characters.")),
|
|
minlength: $.validator.format(_("Please enter at least {0} characters.")),
|
|
rangelength: $.validator.format(_("Please enter a value between {0} and {1} characters long.")),
|
|
range: $.validator.format(_("Please enter a value between {0} and {1}.")),
|
|
max: $.validator.format(_("Please enter a value less than or equal to {0}.")),
|
|
min: $.validator.format(_("Please enter a value greater than or equal to {0}.")),
|
|
phone: $.validator.format(_("Please enter a valid phone number."))
|
|
});
|
|
});
|
|
</script>
|
|
<!-- / validator-strings.inc -->
|