Skip to content

Commit f74e196

Browse files
committed
new license, some optimization for better prestanda
1 parent cfd9645 commit f74e196

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h2>Example of all features</h2>
8888
</p>
8989

9090
<p>
91-
<strong>Date yyyy-mm-dd</strong> <em>validate_date</em><br/>
91+
<strong>Date yyyy-mm-dd</strong> (Custom date format is also possible) <em>validate_date</em><br/>
9292
<input data-validation="validate_date"/>
9393
</p>
9494

jquery.formvalidator.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66
* Available for download at jQuery.com <http://plugins.jquery.com/project/jQueryFormValidtor/>
77
*
8-
* (c) 2011 Victor Jonsson, Sweden.
9-
* Dual licensed under the MIT or GPL Version 2 licenses
10-
*
8+
* $license Creative Commons Erkännande-DelaLika 3.0 Unported License <http://creativecommons.org/licenses/by-sa/3.0/>
119
* $version 1.3.beta
10+
* $stable 1.2 (https://github.com/victorjonsson/jQuery-Form-Validator/zipball/v1.2)
1211
*/
13-
1412
(function($) {
1513
$.extend($.fn, {
1614

@@ -43,8 +41,9 @@
4341
if(help) {
4442
$(this)
4543
.focus(function() {
46-
if($(this).parent().find('.jquery_form_help').length == 0) {
47-
$(this).after(
44+
var $element = $(this);
45+
if($element.parent().find('.jquery_form_help').length == 0) {
46+
$element.after(
4847
$('<span />')
4948
.addClass('jquery_form_help')
5049
.text(help)
@@ -55,9 +54,9 @@
5554
})
5655
.blur(function() {
5756
$(this).parent().find('.jquery_form_help')
58-
.fadeOut('slow', function() {
59-
$(this).remove();
60-
});
57+
.fadeOut('slow', function() {
58+
$(this).remove();
59+
});
6160
});
6261
}
6362
});
@@ -78,6 +77,8 @@
7877
if(typeof attachKeyupEvent == 'undefined')
7978
attachKeyupEvent = true;
8079

80+
var $element = $(this);
81+
8182
var config = {
8283
validationRuleAttribute : 'data-validation',
8384
errorElementClass : 'error', // Class that will be put on elements which value is invalid
@@ -92,33 +93,34 @@
9293
else
9394
language = jQueryFormUtils.LANG;
9495

95-
if (jQueryFormUtils.defaultBorderColor == null && $(this).attr('type') == 'text')
96-
jQueryFormUtils.defaultBorderColor = $(this).css('border-color');
96+
var elementType = $element.attr('type');
97+
if (jQueryFormUtils.defaultBorderColor == null && elementType != 'submit' && elementType != 'checkbox' && elementType != 'radio')
98+
jQueryFormUtils.defaultBorderColor = $element.css('border-color');
9799

98100
// Remove possible error style applied by previous validation
99-
$(this)
101+
$element
100102
.removeClass(config.errorElementClass)
101103
.parent()
102104
.find('.jquery_form_error_message').remove();
103105

104106
if(config.borderColorOnError != '')
105-
$(this).css('border-color', jQueryFormUtils.defaultBorderColor);
107+
$element.css('border-color', jQueryFormUtils.defaultBorderColor);
106108

107-
var validation = jQueryFormUtils.validateInput($(this), language, config);
109+
var validation = jQueryFormUtils.validateInput($element, language, config);
108110

109111
if(validation === true)
110-
$(this).unbind('keyup');
112+
$element.unbind('keyup');
111113
else {
112-
$(this)
114+
$element
113115
.addClass(config.errorElementClass)
114116
.parent()
115117
.append('<span class="jquery_form_error_message">'+validation+'</span>');
116118

117119
if(config.borderColorOnError != '')
118-
$(this).css('border-color', config.borderColorOnError);
120+
$element.css('border-color', config.borderColorOnError);
119121

120122
if(attachKeyupEvent) {
121-
$(this).bind('keyup', function() {
123+
$element.bind('keyup', function() {
122124
$(this).doValidate(language, settings, false);
123125
});
124126
}
@@ -192,17 +194,17 @@
192194
var errorInputs = [];
193195

194196
/** Form instance */
195-
var form = this;
197+
var $form = $(this);
196198

197199
//
198200
// Validate radio buttons
199201
//
200-
$(this).find('input[type=radio]').each(function() {
202+
$form.find('input[type=radio]').each(function() {
201203
var validationRule = $(this).attr(config.validationRuleAttribute);
202204
if (typeof validationRule != 'undefined' && validationRule == 'required') {
203205
var radioButtonName = $(this).attr('name');
204206
var isChecked = false;
205-
form.find('input[name=' + radioButtonName + ']').each(function() {
207+
$form.find('input[name=' + radioButtonName + ']').each(function() {
206208
if ($(this).is(':checked'))
207209
isChecked = true;
208210
});
@@ -217,7 +219,7 @@
217219
//
218220
// Validate element values
219221
//
220-
$(this).find('input,textarea,select').each(function() {
222+
$form.find('input,textarea,select').each(function() {
221223
if (!ignoreInput($(this).attr('name'), $(this).attr('type'))) {
222224

223225
// memorize border color
@@ -228,7 +230,7 @@
228230
$(this),
229231
language,
230232
config,
231-
$(form)
233+
$form
232234
);
233235

234236
if(valid !== true) {
@@ -242,7 +244,7 @@
242244
//
243245
// Reset style and remove error class
244246
//
245-
$(this).find('input,textarea,select')
247+
$form.find('input,textarea,select')
246248
.css('border-color', jQueryFormUtils.defaultBorderColor)
247249
.removeClass(config.errorElementClass);
248250

@@ -271,9 +273,10 @@
271273
var messages = '<strong>' + language.errorTitle + '</strong>';
272274
for (var i = 0; i < errorMessages.length; i++)
273275
messages += '<br />* ' + errorMessages[i];
274-
$(this).children().eq(0).before('<p class="' + config.errorMessageClass + '">' + messages + '</p>');
276+
277+
$form.children().eq(0).before('<p class="' + config.errorMessageClass + '">' + messages + '</p>');
275278
if(config.scrollToTopOnError)
276-
$(window).scrollTop($(form).offset().top - 20);
279+
$(window).scrollTop($form.offset().top - 20);
277280
}
278281

279282
// Display error message below input field
@@ -781,5 +784,5 @@ jQueryFormUtils.lengthRestriction = function(inputElement, maxLengthElement) {
781784
.focus(function() {
782785
$(this).keyup();
783786
})
784-
.keyup();
787+
.trigger('keyup');
785788
};

style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ input, textarea {
6969
-webkit-box-shadow: inset 0 0 5px #EEE;
7070
box-shadow: inset 0 0 5px #EEE;
7171
color: #666;
72+
width: 70%;
73+
}
74+
75+
input[type=checkbox], input[type=radio] {
76+
width:auto;
7277
}
7378

7479
input[type=submit] {

0 commit comments

Comments
 (0)