From eda929361984c5d07030594aed6caa6a3a65560e Mon Sep 17 00:00:00 2001 From: Steve Roberts Date: Wed, 8 Jul 2020 19:19:46 +1000 Subject: [PATCH] Change to new directive that prevents enter default and blurs the input field --- .../directives/disable_enter_with_blur.js.coffee | 9 +++++++++ app/views/shop/products/_searchbar.haml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/darkswarm/directives/disable_enter_with_blur.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/disable_enter_with_blur.js.coffee b/app/assets/javascripts/darkswarm/directives/disable_enter_with_blur.js.coffee new file mode 100644 index 0000000000..1704d4c0f9 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/disable_enter_with_blur.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.directive "disableEnterWithBlur", ()-> + # Stops enter from doing normal enter things, and blurs the input + restrict: 'A' + link: (scope, element, attrs)-> + element.bind "keydown keypress", (e)-> + code = e.keyCode || e.which + if code == 13 + element.blur() + e.preventDefault() diff --git a/app/views/shop/products/_searchbar.haml b/app/views/shop/products/_searchbar.haml index f18d9b9382..bda087f4c7 100644 --- a/app/views/shop/products/_searchbar.haml +++ b/app/views/shop/products/_searchbar.haml @@ -6,7 +6,7 @@ type: 'search', placeholder: t(:products_search), "ng-debounce" => "200", - "ofn-disable-enter" => true} + "disable-enter-with-blur" => true} %a.clear{type: 'button', ng: {show: 'query', click: 'clearQuery()'}, 'focus-search' => true} = image_tag "icn-close.png"