From d2bf6c4845cfdeb812e908d16a0e5acf3562b418 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Mon, 15 Feb 2016 16:56:13 -0800 Subject: [PATCH] Fixes #3676 form submit on dropdown selection --- RELEASE-NOTES.md | 1 + src/definitions/behaviors/form.js | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index df34b2bb75..3fcd0ad12c 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -11,6 +11,7 @@ -**Segment/Message** - Fixed issue where `top attached message` would have no border when attached to `segment` #3619 -**Divider** - Fixed issue where descenders like "g" would be cut off in `horizontal divider` #3585 -**Popup** - Fixed issue where checking `instanceof SVGGraphicsElement` caused error in IE11 #3043 +-**Form Validation / Dropdown** - Fixed issue where using "enter" key in a `search dropdown` could cause a form to be submitted #3676 **Enhancements** - **Build Tools** - Added new `autoInstall` option to allow for Semantic to be installed without user interaction. See [docs explanation](http://www.semantic-ui.com/introduction/advanced-usage.html#Auto-Install) for how to use. #3616 **Thanks @algorithme** diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index c63d7cb35a..b0e1f902fe 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -261,9 +261,12 @@ $.fn.form = function(parameters) { field: { keydown: function(event) { var - $field = $(this), - key = event.which, - keyCode = { + $field = $(this), + key = event.which, + isInput = $field.is(selector.input), + isCheckbox = $field.is(selector.checkbox), + isInDropdown = ($field.closest(selector.uiDropdown).length > 0), + keyCode = { enter : 13, escape : 27 } @@ -274,7 +277,7 @@ $.fn.form = function(parameters) { .blur() ; } - if(!event.ctrlKey && key == keyCode.enter && $field.is(selector.input) && $field.not(selector.checkbox).length > 0 ) { + if(!event.ctrlKey && key == keyCode.enter && isInput && !isInDropdown && !isCheckbox) { if(!keyHeldDown) { $field .one('keyup' + eventNamespace, module.event.field.keyup)