Sha256: 573338d2cfb03167c0c010963426627a5abb08f55a076361f2a3e3c73e408354

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# ---------------------------------------------------------
# DATE SELECT (rails fix)
# ---------------------------------------------------------

@Character.Generic.Helpers.startDateSelect = ($form)->
  updateDateValue = ($wrapper, $input) ->
    selects = $wrapper.children('select')

    day   = $(selects[0]).val()
    month = $(selects[1]).val()
    year  = $(selects[2]).val()

    $input.val("#{ year }-#{ month }-#{ day }")


  # initialize hiddin input and start value
  $form.find('.chr-date-dmy').each (i, el) ->

    $el          = $(this)
    $hiddenInput = $el.children('input[type="hidden"]')

    if $hiddenInput.length == 0
      dateFieldName = $el.children('select').first()
        .attr('name').replace('(3i)', '')
        .replace('(2i)', '')
        .replace('(1i)', '')
      $hiddenInput = $("<input type='hidden' name='#{ dateFieldName }' />").appendTo($el)

    updateDateValue($el, $hiddenInput)


  # remove bad field names
  $form.find('.chr-date-dmy select').attr('name', '')


  # update date on select change
  $form.find('.chr-date-dmy select').on 'change', (e) ->
    $parentDiv   = $(this).parent()
    $hiddenInput = $parentDiv.children('input[type="hidden"]').first()

    updateDateValue($parentDiv, $hiddenInput)


@Character.Generic.Helpers.stopDateSelect = ($form) ->
  $form.find('.chr-date-dmy select').off 'change'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
character-1.0.6 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.5 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.4 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.3 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.2 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.1 app/assets/javascripts/character/generic/helpers/date_select.coffee
character-1.0.0 app/assets/javascripts/character/generic/helpers/date_select.coffee