aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/app
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2017-02-20 14:29:26 +0900
committerGuillermo Iguaran <guilleiguaran@gmail.com>2017-02-20 14:29:55 +0900
commit41c33bd4b2ec3f4a482e6030b6fda15091d81e4a (patch)
tree12a2884bf4e822b80484b4f3b5b2f2f44e840347 /actionview/app
parenta2234c5f68edebe7f842873f0c0d7c53b439861c (diff)
downloadrails-41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.tar.gz
rails-41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.tar.bz2
rails-41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.zip
Import rails-ujs v0.1.0 from rails/rails-ujs
Diffstat (limited to 'actionview/app')
-rw-r--r--actionview/app/assets/javascripts/config.coffee13
-rw-r--r--actionview/app/assets/javascripts/features/remote.coffee12
-rw-r--r--actionview/app/assets/javascripts/rails-ujs.coffee9
-rw-r--r--actionview/app/assets/javascripts/utils/event.coffee2
-rw-r--r--actionview/app/assets/javascripts/utils/form.coffee27
5 files changed, 12 insertions, 51 deletions
diff --git a/actionview/app/assets/javascripts/config.coffee b/actionview/app/assets/javascripts/config.coffee
index 3d4706b0e1..a93325e903 100644
--- a/actionview/app/assets/javascripts/config.coffee
+++ b/actionview/app/assets/javascripts/config.coffee
@@ -1,21 +1,21 @@
#= export Rails
@Rails =
- # Link elements bound by jquery-ujs
+ # Link elements bound by rails-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]'
- # Button elements bound by jquery-ujs
+ # Button elements bound by rails-ujs
buttonClickSelector:
selector: 'button[data-remote]:not([form]), button[data-confirm]:not([form])'
exclude: 'form button'
- # Select elements bound by jquery-ujs
+ # Select elements bound by rails-ujs
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]'
- # Form elements bound by jquery-ujs
+ # Form elements bound by rails-ujs
formSubmitSelector: 'form'
- # Form input elements bound by jquery-ujs
+ # Form input elements bound by rails-ujs
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])'
# Form input elements disabled during form submission
@@ -24,9 +24,6 @@
# Form input elements re-enabled after form submission
formEnableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled'
- # Form required input elements
- requiredInputSelector: 'input[name][required]:not([disabled]), textarea[name][required]:not([disabled])'
-
# Form file input elements
fileInputSelector: 'input[name][type=file]:not([disabled])'
diff --git a/actionview/app/assets/javascripts/features/remote.coffee b/actionview/app/assets/javascripts/features/remote.coffee
index 30a5dc21fa..852587042c 100644
--- a/actionview/app/assets/javascripts/features/remote.coffee
+++ b/actionview/app/assets/javascripts/features/remote.coffee
@@ -4,7 +4,7 @@
matches, getData, setData
fire, stopEverything
ajax, isCrossDomain
- blankInputs, serializeElement
+ serializeElement
} = Rails
# Checks "data-remote" if true to handle the request through a XHR request.
@@ -71,16 +71,6 @@ Rails.handleRemote = (e) ->
)
stopEverything(e)
-# Check whether any required fields are empty
-# In both ajax mode and normal mode
-Rails.validateForm = (e) ->
- form = this
- return if form.noValidate or getData(form, 'ujs:formnovalidate-button')
- # Skip other logic when required values are missing or file upload is present
- blankRequiredInputs = blankInputs(form, Rails.requiredInputSelector, false)
- if blankRequiredInputs.length > 0 and fire(form, 'ajax:aborted:required', [blankRequiredInputs])
- stopEverything(e)
-
Rails.formSubmitButtonClick = (e) ->
button = this
form = button.form
diff --git a/actionview/app/assets/javascripts/rails-ujs.coffee b/actionview/app/assets/javascripts/rails-ujs.coffee
index f96d2eb6fd..df889ce067 100644
--- a/actionview/app/assets/javascripts/rails-ujs.coffee
+++ b/actionview/app/assets/javascripts/rails-ujs.coffee
@@ -14,7 +14,7 @@
refreshCSRFTokens, CSRFProtection
enableElement, disableElement
handleConfirm
- handleRemote, validateForm, formSubmitButtonClick, handleMetaClick
+ handleRemote, formSubmitButtonClick, handleMetaClick
handleMethod
} = Rails
@@ -25,9 +25,9 @@ if jQuery? and not jQuery.rails
CSRFProtection(xhr) unless options.crossDomain
Rails.start = ->
- # Cut down on the number of issues from people inadvertently including jquery_ujs twice
- # by detecting and raising an error when it happens.
- throw new Error('jquery-ujs has already been loaded!') if window._rails_loaded
+ # Cut down on the number of issues from people inadvertently including
+ # rails-ujs twice by detecting and raising an error when it happens.
+ throw new Error('rails-ujs has already been loaded!') if window._rails_loaded
# This event works the same as the load event, except that it fires every
# time the page is loaded.
@@ -58,7 +58,6 @@ Rails.start = ->
delegate document, Rails.inputChangeSelector, 'change', handleRemote
delegate document, Rails.formSubmitSelector, 'submit', handleConfirm
- delegate document, Rails.formSubmitSelector, 'submit', validateForm
delegate document, Rails.formSubmitSelector, 'submit', handleRemote
# Normal mode submit
# Slight timeout so that the submit button gets properly serialized
diff --git a/actionview/app/assets/javascripts/utils/event.coffee b/actionview/app/assets/javascripts/utils/event.coffee
index d25fe8e546..8d3ff007ea 100644
--- a/actionview/app/assets/javascripts/utils/event.coffee
+++ b/actionview/app/assets/javascripts/utils/event.coffee
@@ -6,7 +6,7 @@
# https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
CustomEvent = window.CustomEvent
-if typeof CustomEvent is 'function'
+if typeof CustomEvent isnt 'function'
CustomEvent = (event, params) ->
evt = document.createEvent('CustomEvent')
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
diff --git a/actionview/app/assets/javascripts/utils/form.coffee b/actionview/app/assets/javascripts/utils/form.coffee
index 251113deda..5fa337b518 100644
--- a/actionview/app/assets/javascripts/utils/form.coffee
+++ b/actionview/app/assets/javascripts/utils/form.coffee
@@ -14,7 +14,7 @@ Rails.serializeElement = (element, additionalParam) ->
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
+ 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
@@ -34,28 +34,3 @@ Rails.formElements = (form, selector) ->
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