From 2c0e1a73ed84b6200bb2b6594b094978c80df410 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Thu, 4 Feb 2016 23:53:46 +0000 Subject: [PATCH] FIX Prevent the CMS Hijacking the return keypress in gridfieldaddbydbfield --- .../forms/gridfield/GridFieldAddByDBField.php | 3 ++- js/gridfieldaddbydbfield.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 js/gridfieldaddbydbfield.js diff --git a/code/forms/gridfield/GridFieldAddByDBField.php b/code/forms/gridfield/GridFieldAddByDBField.php index ecd6e6e..8e6323a 100644 --- a/code/forms/gridfield/GridFieldAddByDBField.php +++ b/code/forms/gridfield/GridFieldAddByDBField.php @@ -147,6 +147,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP */ public function getHTMLFragments($gridField) { + Requirements::javascript(BLOGGER_DIR . '/js/gridfieldaddbydbfield.js'); + /** * @var DataList $dataList */ @@ -184,7 +186,6 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP 'add', 'add' ); - $addAction->setAttribute('data-icon', 'add'); $forTemplate = new ArrayData(array()); diff --git a/js/gridfieldaddbydbfield.js b/js/gridfieldaddbydbfield.js new file mode 100644 index 0000000..f6d31e2 --- /dev/null +++ b/js/gridfieldaddbydbfield.js @@ -0,0 +1,20 @@ +(function ($) { + + $.entwine('ss', function ($) { + + /** + * Prevent the CMS hijacking the return key + */ + $('.add-existing-autocompleter input.text').entwine({ + 'onkeydown': function (e) { + if(e.which == 13) { + $parent = $(this).parents('.add-existing-autocompleter'); + $parent.find('button[type="submit"]').click(); + return false; + } + } + }); + + }); + +})(jQuery);