Core: Fix contenteditable detection's regression introduced in #2142 (#2235)

Fixes #2211
Fixes #2214
Fixes #2217
Fixes #2225
Fixes #2233
This commit is contained in:
Brahim Arkni
2018-11-18 11:48:55 +00:00
committed by GitHub
parent 2dfd33c810
commit dd187b016a

View File

@@ -125,6 +125,7 @@ $.extend( $.fn, {
// https://jqueryvalidation.org/rules/ // https://jqueryvalidation.org/rules/
rules: function( command, argument ) { rules: function( command, argument ) {
var element = this[ 0 ], var element = this[ 0 ],
isContentEditable = typeof this.attr( "contenteditable" ) !== "undefined" && this.attr( "contenteditable" ) !== "false",
settings, staticRules, existingRules, data, param, filtered; settings, staticRules, existingRules, data, param, filtered;
// If nothing is selected, return empty object; can't chain anyway // If nothing is selected, return empty object; can't chain anyway
@@ -132,7 +133,7 @@ $.extend( $.fn, {
return; return;
} }
if ( !element.form && element.isContentEditable ) { if ( !element.form && isContentEditable ) {
element.form = this.closest( "form" )[ 0 ]; element.form = this.closest( "form" )[ 0 ];
element.name = this.attr( "name" ); element.name = this.attr( "name" );
} }
@@ -393,9 +394,10 @@ $.extend( $.validator, {
} ); } );
function delegate( event ) { function delegate( event ) {
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
// Set form expando on contenteditable // Set form expando on contenteditable
if ( !this.form && this.isContentEditable ) { if ( !this.form && isContentEditable ) {
this.form = $( this ).closest( "form" )[ 0 ]; this.form = $( this ).closest( "form" )[ 0 ];
this.name = $( this ).attr( "name" ); this.name = $( this ).attr( "name" );
} }
@@ -629,12 +631,14 @@ $.extend( $.validator, {
.not( this.settings.ignore ) .not( this.settings.ignore )
.filter( function() { .filter( function() {
var name = this.name || $( this ).attr( "name" ); // For contenteditable var name = this.name || $( this ).attr( "name" ); // For contenteditable
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
if ( !name && validator.settings.debug && window.console ) { if ( !name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this ); console.error( "%o has no name assigned", this );
} }
// Set form expando on contenteditable // Set form expando on contenteditable
if ( this.isContentEditable ) { if ( isContentEditable ) {
this.form = $( this ).closest( "form" )[ 0 ]; this.form = $( this ).closest( "form" )[ 0 ];
this.name = name; this.name = name;
} }
@@ -689,6 +693,7 @@ $.extend( $.validator, {
elementValue: function( element ) { elementValue: function( element ) {
var $element = $( element ), var $element = $( element ),
type = element.type, type = element.type,
isContentEditable = typeof $element.attr( "contenteditable" ) !== "undefined" && $element.attr( "contenteditable" ) !== "false",
val, idx; val, idx;
if ( type === "radio" || type === "checkbox" ) { if ( type === "radio" || type === "checkbox" ) {
@@ -697,7 +702,7 @@ $.extend( $.validator, {
return element.validity.badInput ? "NaN" : $element.val(); return element.validity.badInput ? "NaN" : $element.val();
} }
if ( element.isContentEditable ) { if ( isContentEditable ) {
val = $element.text(); val = $element.text();
} else { } else {
val = $element.val(); val = $element.val();