Skip to content

Commit

Permalink
Core: Improve elementValue method
Browse files Browse the repository at this point in the history
Do not rewrap several times. Call .val() only when required.

Closes #1055
  • Loading branch information
staabm authored and jzaefferer committed Mar 31, 2014
1 parent 03cd4c9 commit 6c041ed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core.js
Expand Up @@ -558,13 +558,15 @@ $.extend($.validator, {
},

elementValue: function( element ) {
var type = $(element).attr("type"),
val = $(element).val();
var val,
$element = $(element),
type = $element.attr("type");

if ( type === "radio" || type === "checkbox" ) {
return $("input[name='" + $(element).attr("name") + "']:checked").val();
return $("input[name='" + $element.attr("name") + "']:checked").val();
}

val = $element.val();
if ( typeof val === "string" ) {
return val.replace(/\r/g, "");
}
Expand Down

0 comments on commit 6c041ed

Please sign in to comment.