1- /*! HTML5 constraintValidationAPI - v1.0.3 - 2014-04-03
2- * https://github.com/bboyle/html5-constraint-validation-API
3- * Copyright (c) 2014 Ben Boyle; Licensed MIT */
1+ /*! HTML5 constraintValidationAPI - v1.0.4 - 2015-02-02
2+ * https://github.com/bboyle/html5-constraint-validation-API
3+ * Copyright (c) 2015 Ben Boyle; Licensed MIT */
44/*exported initConstraintValidationAPI*/
55if ( jQuery !== 'undefined' ) {
66 ( function ( $ ) {
@@ -15,10 +15,16 @@ if ( jQuery !== 'undefined' ) {
1515 candidateForValidation = 'input, select, textarea' ,
1616
1717 // for feature detection
18- input = $ ( '<input>' ) ,
18+ input = $ ( '<input>' ) . get ( 0 ) ,
1919
2020 // polyfill test
21- polyfill = typeof input [ 0 ] . validity !== 'object' ,
21+ polyfill = typeof input . validity !== 'object' ,
22+
23+
24+ // invalid fields filter
25+ isInvalid = function ( ) {
26+ return ! ( this . disabled || this . validity . valid ) ;
27+ } ,
2228
2329
2430 // manage validity state object
@@ -146,14 +152,24 @@ if ( jQuery !== 'undefined' ) {
146152 }
147153
148154 // NOTE the code below runs in all browsers to polyfill implementation bugs
149- // e.g. Opera 11 on OSX fires submit event even when fields are invalid
155+
156+ // google earth treats all required radio buttons as invalid
157+ // if the only thing stopping submission is a required radio button group...
158+ invalid = form . find ( candidateForValidation ) . filter ( isInvalid ) ;
159+ if ( invalid . length === invalid . filter ( ':radio' ) . length && invalid . length === invalid . filter ( function ( ) {
160+ // radio button has been checked, but is flagged as value missing
161+ return this . validity . valueMissing && $ ( this . form . elements [ this . name ] ) . filter ( ':checked' ) . length > 0 ;
162+ } ) . length ) {
163+ // let submission continue
164+ invalid . removeAttr ( 'required' ) ;
165+ }
166+
167+ // Opera 11 on OSX fires submit event even when fields are invalid
150168 // correct implementations will not invoke this submit handler until all fields are valid
151169
152170 // unless @novalidate
153171 // if there are invalid fields
154- if ( ! novalidate && form . find ( candidateForValidation ) . filter ( function ( ) {
155- return ! ( this . disabled || this . validity . valid ) ;
156- } ) . length > 0 ) {
172+ if ( ! novalidate && form . find ( candidateForValidation ) . filter ( isInvalid ) . length > 0 ) {
157173 // abort submit
158174 event . stopImmediatePropagation ( ) ;
159175 event . preventDefault ( ) ;
@@ -185,7 +201,7 @@ if ( jQuery !== 'undefined' ) {
185201 }
186202
187203 // INPUT validitationMessage
188- if ( typeof input [ 0 ] . validationMessage !== 'string' ) {
204+ if ( typeof input . validationMessage !== 'string' ) {
189205 // set us up the API
190206 candidates . filter ( function ( ) {
191207 return typeof this . validationMessage !== 'string' ;
@@ -195,7 +211,7 @@ if ( jQuery !== 'undefined' ) {
195211 }
196212
197213 // INPUT checkValidity
198- if ( typeof input [ 0 ] . checkValidity !== 'function' ) {
214+ if ( typeof input . checkValidity !== 'function' ) {
199215 // set us up the API
200216 candidates . filter ( function ( ) {
201217 return typeof this . checkValidity !== 'function' ;
@@ -217,7 +233,7 @@ if ( jQuery !== 'undefined' ) {
217233 }
218234
219235 // INPUT setCustomValidity
220- if ( typeof input [ 0 ] . setCustomValidity !== 'function' ) {
236+ if ( typeof input . setCustomValidity !== 'function' ) {
221237 // set us up the API
222238 candidates . filter ( function ( ) {
223239 return typeof this . setCustomValidity !== 'function' ;
0 commit comments