From a5d80d4a1c4a41ec92985e34cac23bac0509e7fb Mon Sep 17 00:00:00 2001
From: "yuuji.yaginuma" <yuuji.yaginuma@gmail.com>
Date: Sun, 3 Sep 2017 16:49:38 +0900
Subject: Does not include disabled element in params

In the case of remote, it should be the same behavior as submitting
HTML form.

Fixes #30444
---
 actionview/app/assets/javascripts/rails-ujs/utils/form.coffee | 2 +-
 actionview/test/ujs/public/test/data-remote.js                | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

(limited to 'actionview')

diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
index 5fa337b518..736cab08db 100644
--- a/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
+++ b/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee
@@ -10,7 +10,7 @@ Rails.serializeElement = (element, additionalParam) ->
   params = []
 
   inputs.forEach (input) ->
-    return unless input.name
+    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
diff --git a/actionview/test/ujs/public/test/data-remote.js b/actionview/test/ujs/public/test/data-remote.js
index 9bbefc18f2..cbbd4e6c92 100644
--- a/actionview/test/ujs/public/test/data-remote.js
+++ b/actionview/test/ujs/public/test/data-remote.js
@@ -191,9 +191,10 @@ asyncTest('submitting form with data-remote attribute should include inputs in a
     .triggerNative('submit')
 })
 
-asyncTest('submitting form with data-remote attribute submits input with matching [form] attribute', 5, function() {
+asyncTest('submitting form with data-remote attribute submits input with matching [form] attribute', 6, function() {
   $('#qunit-fixture')
     .append($('<input type="text" name="user_data" value="value1" form="my-remote-form">'))
+    .append($('<input type="text" name="user_email" value="from@example.com" disabled="disabled" form="my-remote-form">'))
 
   $('form[data-remote]')
     .bindNative('ajax:success', function(e, data, status, xhr) {
@@ -201,6 +202,7 @@ asyncTest('submitting form with data-remote attribute submits input with matchin
       App.assertRequestPath(data, '/echo')
       equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value')
       equal(data.params.user_data, 'value1', 'ajax arguments should have key user_data with right value')
+      equal(data.params.user_email, undefined, 'ajax arguments should not have disabled field')
       App.assertPostRequest(data)
     })
     .bindNative('ajax:complete', function() { start() })
-- 
cgit v1.2.3