Skip to content

Commit

Permalink
Merge pull request #501 from ocadotechnology/438_autocomplete-picker-…
Browse files Browse the repository at this point in the history
…event

fix(autocomplete-picker): Update change event to emit on undefined value
  • Loading branch information
Charlie Frater authored Jul 24, 2018
2 parents cf416a4 + 30977fa commit 6704b1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
@event change [String]
@bugfix nextReleaseVersion
@issue 438
@description
Updated the AutocompletePicker to update the value when setting the value
to @code[undefined]

@description
The event called whenever the input text is updated by the auto
complete object. The data is the value of the input field.
9 changes: 5 additions & 4 deletions modules/autocomplete-picker/main/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ setPickerValue = (picker, results, cause) ->
_.valueText.clear()
if results.length
_.current = results[0]
picker.emit('change', {
cause: cause
value: results[0]
})
_.renderer _.valueText.node(), results[0]
else
_.current = undefined
_.valueText.text(_.options.chooseValueText)

picker.emit('change', {
cause: cause
value: _.current
})

class AutocompletePicker extends hx.EventEmitter
constructor: (selector, items, options = {}) ->
super()
Expand Down
12 changes: 12 additions & 0 deletions modules/autocomplete-picker/test/spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,18 @@ describe 'autocomplete-picker', ->
showstart.should.have.been.called.once()


it 'should emit the "change" event when the value is changed to undefined', ->
testClosedAutocomplete trivialItems, { value: 'a' }, (ap) ->
value = chai.spy()
ap.on 'change', value
ap.value(undefined)
value.should.have.been.called.with({
cause: 'api',
value: undefined
})
value.should.have.been.called.once()


it 'should emit the "change" event when the value is changed', ->
testClosedAutocomplete trivialItems, undefined, (ap) ->
value = chai.spy()
Expand Down

0 comments on commit 6704b1e

Please sign in to comment.