From b8dcfbf6f9ed5076d75569401b7998addbf10947 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 Content-Type: text/plain; charset=utf-8 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. Signed-off-by: Bin Wen Signed-off-by: Marcel de Rooy --- .../bootstrap/en/modules/opac-suggestions.tt | 162 ++++++++++++++++----- opac/opac-suggestions.pl | 6 +- 2 files changed, 130 insertions(+), 38 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 5d4e8b8aef..5ce43f2718 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.size ) %] - { - var FldsRequired = ['[% mandatoryfields.join("','") | html %]']; - 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 bd42478fa8..1d11d75cf4 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -212,7 +212,10 @@ my @mandatoryfields; { last unless ($op eq 'add'); my $fldsreq_sp = C4::Context->preference("OPACSuggestionMandatoryFields") || 'title'; - @mandatoryfields = sort split(/\s*\,\s*/, $fldsreq_sp); + @mandatoryfields = split( ",", $fldsreq_sp ); + foreach (@mandatoryfields) { + $template->param( $_."_required" => 1); + } } $template->param( @@ -224,7 +227,6 @@ $template->param( messages => \@messages, suggestionsview => 1, suggested_by_anyone => $suggested_by_anyone, - mandatoryfields => \@mandatoryfields, patrons_pending_suggestions_count => $patrons_pending_suggestions_count, ); -- 2.11.0