Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update deprecated form selectors (:file, :radio, etc.) #291

Merged
merged 2 commits into from

3 participants

@javierjulio

Shorthand form selectors in jQuery such as :file, :radio, :checkbox and others have been deprecated. I've replaced any instances with the standard type which has always been supported. For example, :file now is input[type=file]. There are a few instances in rails.js where this was already being done so I stuck to the same format (no quotes on attribute value).

Deprecation details: http://api.jquery.com/category/deprecated/.
Form selector deprecation ticket: http://bugs.jquery.com/ticket/9400

Using the standard selector (e.g. input[type=file]) provides better performance in modern browsers.

@javierjulio

Unless I'm mistaken support for several colon prefixed selectors (which this pull request updates to use standard ones) are being removed from jQuery 1.9 which is the next release. Today the jQuery team released 1.9 beta 1.

@JangoSteve
Collaborator

Thank you. I'll be able to take a look at this in the next week I think. We'll have to figure out how to make this work also with jQuery 1.8, or wait until 1.9 comes out of beta.

@javierjulio

Is their something I'm missing that it wouldn't work with jQuery 1.8? Or it just needs to be tested/validated? This will work with previous versions of jQuery since the standard selector has always been supported, its just the shorthand versions are getting phased out (most, not all). I wasn't sure if tests needed to be written for this case since its jQuery functionality. Happy to help out though. Thanks.

@JangoSteve
Collaborator

Needs to be tested/validated.

@JangoSteve
Collaborator

By the way, these weren't removed in jquery 1.9, but I'll take a look.

@neerajdotname
Collaborator

This change is backward compatible and as per http://api.jquery.com/file-selector/

Because :file is a jQuery extension and not part of the CSS specification, queries using :file cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use [type="file"] instead.

@neerajdotname neerajdotname merged commit a2a7721 into rails:master
@JangoSteve
Collaborator

Awesome, thanks for catching us up on all these, @neerajdotname. I've been a bit swamped.

@javierjulio

Awesome! Glad to see this change go through. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 src/rails.js
View
6 src/rails.js
@@ -82,7 +82,7 @@
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
// Form file input elements
- fileInputSelector: 'input:file',
+ fileInputSelector: 'input[type=file]',
// Link onClick disable selector with possible reenable after remote submission
linkDisableSelector: 'a[data-disable-with]',
@@ -257,12 +257,12 @@
allInputs.each(function() {
input = $(this);
- valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val();
+ valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
// If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
if (!valueToCheck === !nonBlank) {
// Don't count unchecked required radio if other radio with same name is checked
- if (input.is(':radio') && allInputs.filter('input:radio:checked[name="' + input.attr('name') + '"]').length) {
+ if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
return true; // Skip to next input
}
Something went wrong with that request. Please try again.