Sha256: aa1a6a8c45cda0840e3c7e644372406604b6ec1a7196836409273f263a34d63e

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

class App.ResourceForm
  constructor: (@el) ->
    # initialize some stuff
    inputForm = null


  #
  # make sure fields with values do not have their labels obscuring your view
  #
  setLabels: (selector) ->
    $(selector).each () ->
      try
        fld = '#'+$(this).attr('for')
        $(this).addClass('active') unless $(fld)[0].value.nil?
      catch
        #console.log this

  #
  # initializeForm
  # on pages with a FORM element - like show, new and edit
  # prepare the FORM element
  #
  initializeForm: (f) ->
    @inputForm = f
    #
    # Initialize SELECT's
    #
    $('select').each () ->
      # remove span.caret's from previous 'runs' - however that happens
      $(this).parent().parent().find('span.caret').remove()
      $(this).material_select()

    #
    # make labels on fields with content move out of the way
    #
    @setLabels('.input-field label')

    #
    # Initialize INPUT TYPE='DATE'
    #
    #   %input.datepicker{ type:"date" }
    #
    $('.datepicker').pickadate
      selectMonths: true, # Creates a dropdown to control month
      selectYears: 15     # Creates a dropdown of 15 years to control year


  prepare: ->

    try
      #
      # If this page has FORM element(s)
      #
      $('form').first().map (k,f) =>
        @initializeForm(f)

    catch error
      alert 'App.ResourceForm did not prepare!'
      console.log error

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
abstracted-0.2.7 app/assets/javascripts/abstracted/app.resource_form.coffee
abstracted-0.2.6 app/assets/javascripts/abstracted/app.resource_form.coffee
abstracted-0.2.5 app/assets/javascripts/abstracted/app.resource_form.coffee