Bug 9120: Prevent form submission on adding tags - OPAC
authorJonathan Druart <jonathan.druart@biblibre.com>
Wed, 18 Mar 2015 16:21:42 +0000 (17:21 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Mon, 30 Mar 2015 16:46:44 +0000 (13:46 -0300)
At the OPAC, if the user adds tags pressing 'Enter', the page is
reloaded and the tags are not added.
To prevent that, this patch suggests to block the "press enter" event on
the inputs.

Test plan:
0/ Confirm the bad behavior, without this patch.
1/ Apply this patch and confirm nothing happen on pressing enter when
the focus is on the add tag input (At the opac, on the result view).

Patch works as expected.
Signed-off-by: Marc Veron <veron@veron.ch>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt

index 2622b59..d01ddeb 100644 (file)
                                                                 <span class="actions"><a class="tag_add" id="tag_add[% SEARCH_RESULT.biblionumber %]" href="#">Add tag</a></span>
                                                                 <div id="tagform[% SEARCH_RESULT.biblionumber %]" class="tag_results_input" style="display:none;">
                                                                         <label for="newtag[% SEARCH_RESULT.biblionumber %]">New tag(s), separated by a comma:</label>
-                                                                        <input type="text" name="newtag[% SEARCH_RESULT.biblionumber %]" id="newtag[% SEARCH_RESULT.biblionumber %]" maxlength="100" />
+                                                                        <input type="text" name="newtag[% SEARCH_RESULT.biblionumber %]" id="newtag[% SEARCH_RESULT.biblionumber %]" class="newtag" maxlength="100" />
                                                                         <input name="tagbutton" class="btn btn-small tagbutton" title="[% SEARCH_RESULT.biblionumber %]" type="submit" value="Add" />
                                                                         <a class="cancel_tag_add" id="cancel[% SEARCH_RESULT.biblionumber %]" href="#">(done)</a>
                                                                 </div>
@@ -915,6 +915,10 @@ $(document).ready(function(){
         });
 [% END %]
 
+$("input.newtag").on('keydown', function(e){
+    if (e.keyCode == 13) { e.preventDefault(); }
+});
+
 });
 //]]>
 </script>