diff options
author | Leonel Galán <leonel@getstealz.com> | 2017-04-03 22:59:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 22:59:43 -0400 |
commit | 8648f289f01656b2258687126108c389127108e0 (patch) | |
tree | 1ccb15f72f00d8c30497ad4e48f203545dd3383b /actionview/app/assets/javascripts/utils/form.coffee | |
parent | 28b3582aa2cd6007c708134b911b3f360ad5d659 (diff) | |
parent | e8c33349bfabca28996ac74d344d69c7aaffec50 (diff) | |
download | rails-8648f289f01656b2258687126108c389127108e0.tar.gz rails-8648f289f01656b2258687126108c389127108e0.tar.bz2 rails-8648f289f01656b2258687126108c389127108e0.zip |
Merge branch 'master' into bug/filtered_parameters_class
Diffstat (limited to 'actionview/app/assets/javascripts/utils/form.coffee')
-rw-r--r-- | actionview/app/assets/javascripts/utils/form.coffee | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/actionview/app/assets/javascripts/utils/form.coffee b/actionview/app/assets/javascripts/utils/form.coffee deleted file mode 100644 index 251113deda..0000000000 --- a/actionview/app/assets/javascripts/utils/form.coffee +++ /dev/null @@ -1,61 +0,0 @@ -#= 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 unless input.name - if matches(input, 'select') - toArray(input.options).forEach (option) -> - params.push(name: input.name, value: option.value) if option.selected - else if input.type isnt 'radio' and input.type isnt 'checkbox' or input.checked - 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)) - -# Helper function which checks for blank inputs in a form that match the specified CSS selector -Rails.blankInputs = (form, selector, nonBlank) -> - foundInputs = [] - requiredInputs = toArray(form.querySelectorAll(selector or 'input, textarea')) - checkedRadioButtonNames = {} - - requiredInputs.forEach (input) -> - if input.type is 'radio' - # Don't count unchecked required radio as blank if other radio with same name is checked, - # regardless of whether same-name radio input has required attribute or not. The spec - # states https://www.w3.org/TR/html5/forms.html#the-required-attribute - radioName = input.name - # Skip if we've already seen the radio with this name. - unless checkedRadioButtonNames[radioName] - # If none checked - if form.querySelectorAll("input[type=radio][name='#{radioName}']:checked").length == 0 - radios = form.querySelectorAll("input[type=radio][name='#{radioName}']") - foundInputs = foundInputs.concat(toArray(radios)) - # We only need to check each name once. - checkedRadioButtonNames[radioName] = radioName - else - valueToCheck = if input.type is 'checkbox' then input.checked else !!input.value - foundInputs.push(input) if valueToCheck is nonBlank - foundInputs |