Skip to content

Commit a053aa0

Browse files
authored
Remove dead selector aliases (#1018)
Drop `selectors.inputs` and `selectors.validate_inputs` from the runtime surface. They stopped participating in validation when 1e22209 replaced jQuery traversal with `form.elements`, DOM helpers, and `dataset.csvValidate` checks, leaving `selectors.forms` as the only remaining selector used at runtime. Keeping these dead fields around suggests selector-driven behavior is still supported when the 24.x API is intentionally DOM-first. Reintroducing them would be a regression because it encourages users to couple to unsupported internals and points the runtime back toward the old descendant-query model that the jQuery removal intentionally removed. It is now possible to validate form-associated input that lives outside the form subtree. That behavior is new with the `form.elements`-based implementation and was not possible before, because the old `jQuery.find(...)` path could only reach descendants of the form element.
1 parent a6b11f3 commit a053aa0

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

dist/client-side-validations.esm.js

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/client-side-validations.js

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ const ClientSideValidations = {
250250
}
251251
},
252252
selectors: {
253-
inputs: 'input:not([type="submit"]):not([type="button"])[name], select[name], textarea[name]',
254-
validate_inputs: 'input[data-csv-validate]:not([type="submit"]):not([type="button"]), select[data-csv-validate], textarea[data-csv-validate]',
255253
forms: 'form[data-client-side-validations]'
256254
},
257255
validators: {

test/javascript/public/test/form_builders/validateForm.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,39 @@ QUnit.test('Decorative (without name) inputs aren\'t validated (async)', functio
204204
}, 250)
205205
})
206206

207+
QUnit.test('Associated inputs outside the form are validated on submit (async)', function (assert) {
208+
var done = assert.async()
209+
var fixture = document.getElementById('qunit-fixture')
210+
var form = document.getElementById('new_user')
211+
var input = document.getElementById('user_name')
212+
var outsideInput = document.createElement('input')
213+
214+
input.value = 'Test'
215+
216+
outsideInput.name = 'user[name]'
217+
outsideInput.id = 'user_name_external'
218+
outsideInput.type = 'text'
219+
outsideInput.setAttribute('form', form.id)
220+
fixture.appendChild(outsideInput)
221+
222+
ClientSideValidations.validate(form)
223+
224+
assert.ok(outsideInput.dataset.csvValidate)
225+
226+
form.requestSubmit()
227+
228+
setTimeout(function () {
229+
var iframe = document.querySelector('iframe')
230+
var response = iframe && iframe.contentDocument && iframe.contentDocument.querySelector('#response')
231+
232+
assert.notOk(response)
233+
assert.notOk(input.parentElement.classList.contains('field_with_errors'))
234+
assert.ok(outsideInput.parentElement.classList.contains('field_with_errors'))
235+
assert.ok(outsideInput.parentElement.querySelector('label.message'))
236+
done()
237+
}, 250)
238+
})
239+
207240
QUnit.test('Resetting client side validations', function (assert) {
208241
var form = document.getElementById('new_user')
209242
var input = document.getElementById('user_name')

vendor/assets/javascripts/rails.validations.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@
303303
}
304304
},
305305
selectors: {
306-
inputs: 'input:not([type="submit"]):not([type="button"])[name], select[name], textarea[name]',
307-
validate_inputs: 'input[data-csv-validate]:not([type="submit"]):not([type="button"]), select[data-csv-validate], textarea[data-csv-validate]',
308306
forms: 'form[data-client-side-validations]'
309307
},
310308
validators: {

0 commit comments

Comments
 (0)