Sha256: 0b5481a6db7a2e8528011668d048c4c2020b0f627bd3b1f7016b43497eb3e5b2

Contents?: true

Size: 1.35 KB

Versions: 19

Compression:

Stored size: 1.35 KB

Contents

Luca.core.Field = Luca.View.extend
  className: 'luca-ui-text-field luca-ui-field'
  
  isField: true

  template: 'fields/text_field'
   
  labelAlign: 'top'

  hooks:[
    "before:validation",
    "after:validation",
    "on:change"
  ]

  # see: http://twitter.github.com/bootstrap/base-css.html
  statuses: [
    "warning"
    "error"
    "success"
  ]

  initialize: (@options={})->
    _.extend @, @options
    Luca.View::initialize.apply(@, arguments)

    @input_id ||= _.uniqueId('field') 
    @input_name ||= @name 
    @helperText ||= ""
    @label ||= "*#{ @label }" if @required and not @label?.match(/^\*/)
    @inputStyles ||= ""

    @disable() if @disabled

    @updateState( @state )
    @placeHolder ||= ""

  beforeRender: ()->
    if Luca.enableBootstrap
      @$el.addClass('control-group')

    @$el.addClass('required') if @required

    @$el.html Luca.templates[ @template ]( @ )
    @input = $('input', @el)
  
  change_handler: (e)->
    @trigger "on:change", @, e 

  disable: ()->
    $("input",@el).attr('disabled', true)
  
  enable: ()->
    $("input", @el).attr('disabled', false)  

  getValue: ()-> 
    @input.attr('value')

  render: ()->
    $( @container ).append( @$el )

  setValue: (value)-> 
    @input.attr('value', value)
  
  updateState: (state)->
    _( @statuses ).each (cls)=> 
      @$el.removeClass(cls)
      @$el.addClass(state)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
luca-0.8.3 src/core/field.coffee
luca-0.8.2 src/core/field.coffee
luca-0.8.06 src/core/field.coffee
luca-0.8 src/core/field.coffee
luca-0.7.92 src/core/field.coffee
luca-0.7.91 src/core/field.coffee
luca-0.7.9 src/core/field.coffee
luca-0.7.8 src/core/field.coffee
luca-0.7.7 src/core/field.coffee
luca-0.7.6 src/core/field.coffee
luca-0.7.5 src/core/field.coffee
luca-0.7.4 src/core/field.coffee
luca-0.7.3 src/core/field.coffee
luca-0.7.2 src/core/field.coffee
luca-0.7.0 src/core/field.coffee
luca-0.6.9 src/core/field.coffee
luca-0.6.8 src/core/field.coffee
luca-0.6.7 src/core/field.coffee
luca-0.6.6 src/core/field.coffee