Sha256: 1c13efd63a65000ab1320f1c772954350efdbb8c7375a1682f94ff468e429b26

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

_.def('Luca.core.Field').extends('Luca.View').with

  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

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

    @disable() if @disabled

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

    Luca.View::initialize.apply(@, arguments)

  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

3 entries across 3 versions & 1 rubygems

Version Path
luca-0.9.2 src/core/field.coffee
luca-0.9.1 src/core/field.coffee
luca-0.9.0 src/core/field.coffee