Sha256: 5f786e8dc04aa65cb26b4cf48b4362a5a302fdecb0ec2678e3983153ac30ddee

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

class Tao.Form.Select.ResultBase extends TaoComponent

  @tag 'tao-select-result'

  @attribute 'selected', 'clearable', type: 'boolean'

  @attribute 'disabled', type: 'boolean', observe: true

  _connected: ->
    @field = @jq.find 'select'
    @_bind()

  _disconnected: ->
    @off()

  _bind: ->
    @on 'click', 'select', =>
      @trigger 'tao:activeClick'
      false

    @on 'click', '.link-clear', (e) =>
      return if @disabled
      @clear() && @trigger('tao:clear')
      false

  selectOption: (option) ->
    return false unless option
    @selectedOption = option
    @selected = true
    @_setSelectedOption option
    @jq.find('.selected-text').text option.text
    true

  unselectOption: (option = @selectedOption) ->
    return false unless option
    @selectedOption = null
    @selected = false
    @_setSelectedOption false
    @jq.find('.selected-text').text ''
    true

  _setSelectedOption: (option) ->
    @field.find('option:selected').prop 'selected', false
    return unless option

    $option = @field.find("option[value='#{option.value}']")
    $option = @_generateOption(option) unless $option.length > 0
    $option.prop 'selected', true

  _generateOption: (option) ->
    $option = $('<option>', test: option.text, value: option.value).appendTo(@field)
    @field.trigger 'tao:addOption', option, $option
    $option

  clear: ->
    @unselectOption()

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tao_form-0.1.9 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.8 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.7 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.6 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.5 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.4 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee
tao_form-0.1.3 lib/assets/javascripts/tao/form/shared/fields/select/result/base.coffee