From 13e144f9ed5551815277ff464aa32d946bc7f47b Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 20 Mar 2019 18:58:02 +0000 Subject: [PATCH] Bug 22657: Remove JavaScript from OPAC suggestion validation of required fields This patch modifies the OPAC suggestion form so that it doesn't require JavaScript for form validation. This change doesn't alter the behavior of the form for users but does fit with the general goal of progressive enhancement for the OPAC. The patch adds "required" labels to required fields to better identify required fields. To test, apply the patch and make sure there are required fields specified in the OPACSuggestionMandatoryFields system preference. - Log in to the OPAC and go to Your purchase suggestions -> New purchase suggestion. - Verify that the fields specified in OPACSuggestionMandatoryFields are highlighted and marked "required." - Verify that you can't submit the form without filling out these fields. --- .../bootstrap/en/modules/opac-suggestions.tt | 162 ++++++++++++++++----- opac/opac-suggestions.pl | 11 +- 2 files changed, 134 insertions(+), 39 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index f560e64..5ce43f2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -43,42 +43,145 @@
    -
  1. -
  2. +
  3. + [% IF ( title_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  4. +
  5. + [% IF ( author_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  6. - + [% IF ( copyrightdate_required ) %] + + + Required + [% ELSE %] + + + [% END %]
  7. -
  8. -
  9. -
  10. -
  11. -
  12. -
  13. - [% PROCESS 'av-build-dropbox.inc' name="itemtype", category="SUGGEST_FORMAT", size = 20 %] +
  14. + [% IF ( isbn_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  15. +
  16. + [% IF ( publishercode_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  17. +
  18. + [% IF ( collectiontitle_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  19. +
  20. + [% IF ( place_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  21. +
  22. + [% IF ( quantity_required ) %] + + + Required + [% ELSE %] + + + [% END %] +
  23. +
  24. + [% IF ( itemtype_required ) %] + + [% PROCESS 'av-build-dropbox.inc' name="itemtype", category="SUGGEST_FORMAT", size = 20 %] + Required + [% ELSE %] + + [% PROCESS 'av-build-dropbox.inc' name="itemtype", category="SUGGEST_FORMAT", size = 20 %] + [% END %]
  25. [% IF branchcode %] -
  26. - +
  27. + [% IF ( branchcode_required ) %] + + + Required + [% ELSE %] + + + [% END %]
  28. [% END %] [% IF ( patron_reason_loop ) %]
  29. - - + [% IF ( patronreason_required ) %] + + + Required + [% ELSE %] + + + [% END %]
  30. [% END %]
  31. - - + [% IF ( note_required ) %] + + + Required + [% ELSE %] + + + [% END %]
  32. @@ -339,19 +442,6 @@ return true; }); [% END %] - [% IF ( op_add && mandatoryfields ) %] - { - var FldsRequired = [[% mandatoryfields | $raw %]]; - for (var i = 0; i < FldsRequired.length; i++) { - var rq_input = $('#' + FldsRequired[i]); - if (rq_input.length != 1) continue; - $(rq_input).attr("required", "required"); - var rq_label = $("label[for=" + rq_input.attr("id") + "]"); - if (rq_label.length != 1) continue; - $(rq_label).addClass('required'); - } - } - [% END %] }); //]]> diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index cf562fb..9c2b861 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -208,13 +208,19 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { $template->param( branchcode => $branchcode ); } -my $mandatoryfields = ''; +my @mandatoryfields; + { last unless ($op eq 'add'); my $fldsreq_sp = C4::Context->preference("OPACSuggestionMandatoryFields") || 'title'; - $mandatoryfields = join(', ', (map { '"'.$_.'"'; } sort split(/\s*\,\s*/, $fldsreq_sp))); + @mandatoryfields = split( ",", $fldsreq_sp ); + foreach (@mandatoryfields) { + $template->param( $_."_required" => 1); + } } + + $template->param( %$suggestion, suggestions_loop => $suggestions_loop, @@ -224,7 +230,6 @@ $template->param( messages => \@messages, suggestionsview => 1, suggested_by_anyone => $suggested_by_anyone, - mandatoryfields => $mandatoryfields, patrons_pending_suggestions_count => $patrons_pending_suggestions_count, ); -- 2.1.4