|
@@ -1,22 +1,23 @@
|
|
|
class App.SearchableSelect extends Spine.Controller
|
|
|
|
|
|
events:
|
|
|
- 'input .js-input': 'onInput'
|
|
|
- 'blur .js-input': 'onBlur'
|
|
|
- 'focus .js-input': 'onFocus'
|
|
|
- 'focus .js-shadow': 'onShadowFocus'
|
|
|
- 'change .js-shadow': 'onShadowChange'
|
|
|
- 'click .js-option': 'selectItem'
|
|
|
- 'click .searchableSelect-option-text': 'selectItem'
|
|
|
- 'click .searchableSelect-option-arrow': 'navigateIn'
|
|
|
- 'click .js-back': 'navigateOut'
|
|
|
- 'mouseenter .js-option': 'highlightItem'
|
|
|
- 'mouseenter .js-enter': 'highlightItem'
|
|
|
- 'mouseenter .js-back': 'highlightItem'
|
|
|
- 'shown.bs.dropdown': 'onDropdownShown'
|
|
|
- 'hidden.bs.dropdown': 'onDropdownHidden'
|
|
|
- 'keyup .js-input': 'onKeyUp'
|
|
|
- 'click .js-remove': 'removeThisToken'
|
|
|
+ 'input .js-input': 'onInput'
|
|
|
+ 'blur .js-input': 'onBlur'
|
|
|
+ 'focus .js-input': 'onFocus'
|
|
|
+ 'focus .js-shadow': 'onShadowFocus'
|
|
|
+ 'change .js-shadow': 'onShadowChange'
|
|
|
+ 'click .js-option': 'selectItem'
|
|
|
+ 'click .js-option .searchableSelect-option-text': 'selectItem'
|
|
|
+ 'click .js-enter .searchableSelect-option-text': 'navigateInOrSelectItem'
|
|
|
+ 'click .searchableSelect-option-arrow': 'navigateIn'
|
|
|
+ 'click .js-back': 'navigateOut'
|
|
|
+ 'mouseenter .js-option': 'highlightItem'
|
|
|
+ 'mouseenter .js-enter': 'highlightItem'
|
|
|
+ 'mouseenter .js-back': 'highlightItem'
|
|
|
+ 'shown.bs.dropdown': 'onDropdownShown'
|
|
|
+ 'hidden.bs.dropdown': 'onDropdownHidden'
|
|
|
+ 'keyup .js-input': 'onKeyUp'
|
|
|
+ 'click .js-remove': 'removeThisToken'
|
|
|
|
|
|
elements:
|
|
|
'.js-dropdown': 'dropdown'
|
|
@@ -288,6 +289,10 @@ class App.SearchableSelect extends Spine.Controller
|
|
|
@input.val value
|
|
|
@shadowInput.val key
|
|
|
|
|
|
+ navigateInOrSelectItem: (event) ->
|
|
|
+ return @selectItem(event) if @attribute.multiple
|
|
|
+ return @navigateIn(event)
|
|
|
+
|
|
|
selectItem: (event) ->
|
|
|
currentText = $(event.target).text().trim()
|
|
|
return if !currentText
|
|
@@ -300,6 +305,8 @@ class App.SearchableSelect extends Spine.Controller
|
|
|
|
|
|
navigateIn: (event) ->
|
|
|
event.stopPropagation()
|
|
|
+ if !@attribute.multiple
|
|
|
+ @selectItem(event)
|
|
|
@navigateDepth(1)
|
|
|
|
|
|
navigateOut: (event) ->
|
|
@@ -512,8 +519,14 @@ class App.SearchableSelect extends Spine.Controller
|
|
|
|
|
|
addValueToShadowInput: (currentText, dataId) ->
|
|
|
@input.val('')
|
|
|
- return if @shadowInput.val().includes("#{dataId}") if @shadowInput.val() # cast dataId to string before check
|
|
|
- @currentData = {name: currentText, value: dataId}
|
|
|
+
|
|
|
+ if @attribute.multiple
|
|
|
+ return if @shadowInput.val().includes("#{dataId}") if @shadowInput.val() # cast dataId to string before check
|
|
|
+ @currentData = {name: currentText, value: dataId}
|
|
|
+ else
|
|
|
+ @currentData = {name: currentText, value: dataId}
|
|
|
+ return if @shadowInput.val().includes("#{dataId}") if @shadowInput.val() # cast dataId to string before check
|
|
|
+
|
|
|
@shadowInput.append($('<option/>').attr('selected', true).attr('value', @currentData.value).text(@currentData.name))
|
|
|
@onShadowChange()
|
|
|
|