Sha256: 8e25f213c3baed4a690466e93dfe784a06dbbb9a012b12a166820ab2e1f8cccb

Contents?: true

Size: 1.2 KB

Versions: 47

Compression:

Stored size: 1.2 KB

Contents

#= require ./dom

{ matches } = Rails

toArray = (e) -> Array.prototype.slice.call(e)

Rails.serializeElement = (element, additionalParam) ->
  inputs = [element]
  inputs = toArray(element.elements) if matches(element, 'form')
  params = []

  inputs.forEach (input) ->
    return if !input.name || input.disabled
    if matches(input, 'select')
      toArray(input.options).forEach (option) ->
        params.push(name: input.name, value: option.value) if option.selected
    else if input.checked or ['radio', 'checkbox', 'submit'].indexOf(input.type) == -1
      params.push(name: input.name, value: input.value)

  params.push(additionalParam) if additionalParam

  params.map (param) ->
    if param.name?
      "#{encodeURIComponent(param.name)}=#{encodeURIComponent(param.value)}"
    else
      param
  .join('&')

# Helper function that returns form elements that match the specified CSS selector
# If form is actually a "form" element this will return associated elements outside the from that have
# the html form attribute set
Rails.formElements = (form, selector) ->
  if matches(form, 'form')
    toArray(form.elements).filter (el) -> matches(el, selector)
  else
    toArray(form.querySelectorAll(selector))

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.9.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.9.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.14 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.13 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.12 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.11 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
jets-1.8.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee