Skip to content

Commit e9de65c

Browse files
committed
Merge pull request victorjonsson#34 from Repkit/master
fix validation for elements named as array element[field]
2 parents 2f9376a + 54f5ccc commit e9de65c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

example.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
99

1010
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
11-
<script type="text/javascript" src="jquery.formvalidator.min.js?upd=1.5.1"></script>
11+
<script type="text/javascript" src="jquery.formvalidator.js"></script>
1212

1313
<link href="style.css?upd=1.5" type="text/css" rel="stylesheet"/>
1414

@@ -180,6 +180,12 @@ <h2>Example of all features</h2>
180180
<em>data-validation-if-checked=&quot;my_checkbox&quot; data-validation=&quot;validate_email&quot;</em>
181181
<input type="text" data-validation="validate_email" data-validation-if-checked="my_checkbox"/>
182182
</p>
183+
<p>
184+
<strong>Elements named as array validation</strong>
185+
<em>data-validation=&quot;validate_confirmation validate_email&quot;</em>
186+
<input name="customer[email]" type="text" data-validation="validate_confirmation validate_email">
187+
<input name="customer[email]_confirmation" type="text">
188+
</p>
183189
<p>
184190
<strong>Length restriction</strong>
185191
<span class="chars_left">

jquery.formvalidator.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
* @param settings
164164
*/
165165
validate : function(language, settings) {
166-
167166
/*
168167
* Config
169168
*/
@@ -215,18 +214,16 @@
215214
// Validate element values
216215
//
217216
$form.find('input,textarea,select').each(function() {
218-
219217
var $el = $(this);
220218
var elementType = $el.attr('type');
221219
if (!jQueryFormUtils.ignoreInput($el.attr('name'), elementType, config)) {
222-
223220
// input of type radio
224221
if(elementType === 'radio') {
225222
var validationRule = $el.attr(config.validationRuleAttribute);
226223
if (typeof validationRule != 'undefined' && validationRule === 'required') {
227224
var radioButtonName = $el.attr('name');
228225
var isChecked = false;
229-
$form.find('input[name=' + radioButtonName + ']').each(function() {
226+
$form.find('input[name="' + radioButtonName + '"]').each(function() {
230227
if ($(this).is(':checked')) {
231228
isChecked = true;
232229
return false;
@@ -980,11 +977,10 @@ jQueryFormUtils.validate = function(value, el, language, config, form) {
980977
if (validationRules.indexOf('validate_swesc') > -1 && !jQueryFormUtils.validateSwedishSecurityNumber(value)) {
981978
return validationErrorMsg || language.badSecurityNumber;
982979
}
983-
984980
// confirmation
985981
if (validationRules.indexOf('validate_confirmation') > -1 && typeof(form) != 'undefined') {
986982
var conf = '';
987-
var confInput = form.find('input[name=' + el.attr('name') + '_confirmation]').eq(0);
983+
var confInput = form.find('input[name="' + el.attr('name') + '_confirmation"]').eq(0);
988984
if (confInput) {
989985
conf = confInput.val();
990986
}

0 commit comments

Comments
 (0)