Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

3 participants

Javier Julio Steve Schwartz Neeraj Singh
Javier Julio

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.

Javier Julio

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.

Steve Schwartz
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.

Javier Julio

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.

Steve Schwartz
Collaborator

Needs to be tested/validated.

Steve Schwartz
Collaborator

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

Neeraj Singh
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.

Neeraj Singh neerajdotname merged commit a2a7721 into from
Steve Schwartz
Collaborator

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

Javier Julio

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
6 src/rails.js
View
@@ -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.