Skip to content

Commit

Permalink
Escape the name when looking for required radio buttons. Fixes Issue #17
Browse files Browse the repository at this point in the history


* Return unit testing to default build
* Add unit test for Issue #17
  • Loading branch information
craig-davis committed Apr 3, 2013
1 parent 83058fc commit 8da1277
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = function (grunt) {
},
src: {
files: '<%= jshint.src.src %>',
tasks: ['jshint:src', 'concat', 'uglify'] //, 'qunit']
tasks: ['jshint:src', 'concat', 'uglify', 'qunit']
},
test: {
files: '<%= jshint.test.src %>',
Expand All @@ -101,7 +101,7 @@ module.exports = function (grunt) {
});

// Default task.
grunt.registerTask('default', ['jshint',/*'qunit', */ 'clean', 'concat', 'cssmin', 'uglify']);
grunt.registerTask('default', ['jshint','qunit', 'clean', 'concat', 'cssmin', 'uglify']);

// Alias this to make it standard across my repos. (Jasmine v. QUnit)
grunt.registerTask('test', ['qunit']);
Expand Down
15 changes: 10 additions & 5 deletions dist/uni-form-validation.jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Uni-Form - v1.5.0 - 2013-03-31
/*! Uni-Form - v1.5.0 - 2013-04-03
* http://sprawsm.com/uni-form/
* Copyright (c) 2013 Dragan Babic; Licensed MIT */
//
Expand Down Expand Up @@ -175,9 +175,9 @@

// Set the form focus class and remove any classes other than the focus
// class and then hide the default label text
$form.find(options.field_selector).on('focus', function (e) {
$form.find(options.field_selector).on('focus', function () {
var $input = $(this);
window.console.log(e);

$form // Remove any other focus highlighting
.find('.' + options.focused_class)
.removeClass(options.focused_class);
Expand Down Expand Up @@ -405,23 +405,28 @@ window.console.log(e);

(function ($) {

var escapeStr;

$.uniform = $.uniform || {};

// Hold a collection of the various form validators
$.uniform.validators = {};

escapeStr = function (str) {
return (str) ? str.replace(/([ #;&,.+*~\':"!\^$\[\]()=>|\/@])/g,'\\$1'): str;
};

// Value of field is not empty, whitespace will be counted as empty
$.uniform.validators.required = function ($field, caption) {
var name;
if ($field.is(':radio')) {
name = $field.attr('name');
name = escapeStr($field.attr('name'));
if ($("input[name=" + name + "]:checked").length) {
return true;
}
return $.uniform.i18n('req_radio', caption);
}
if ($field.is(':checkbox')) {
name = $field.attr('name');
if ($field.is(":checked")) { return true; }
return $.uniform.i18n('req_checkbox', caption);
}
Expand Down
4 changes: 2 additions & 2 deletions dist/uni-form-validation.jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/uni-form.jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Uni-Form - v1.5.0 - 2013-03-31
/*! Uni-Form - v1.5.0 - 2013-04-03
* http://sprawsm.com/uni-form/
* Copyright (c) 2013 Dragan Babic; Licensed MIT */
//
Expand Down
2 changes: 1 addition & 1 deletion dist/uni-form.jquery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/uni-form-validation.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@

// Set the form focus class and remove any classes other than the focus
// class and then hide the default label text
$form.find(options.field_selector).on('focus', function (e) {
$form.find(options.field_selector).on('focus', function () {
var $input = $(this);
window.console.log(e);

$form // Remove any other focus highlighting
.find('.' + options.focused_class)
.removeClass(options.focused_class);
Expand Down
9 changes: 7 additions & 2 deletions src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@

(function ($) {

var escapeStr;

$.uniform = $.uniform || {};

// Hold a collection of the various form validators
$.uniform.validators = {};

escapeStr = function (str) {
return (str) ? str.replace(/([ #;&,.+*~\':"!\^$\[\]()=>|\/@])/g,'\\$1'): str;
};

// Value of field is not empty, whitespace will be counted as empty
$.uniform.validators.required = function ($field, caption) {
var name;
if ($field.is(':radio')) {
name = $field.attr('name');
name = escapeStr($field.attr('name'));
if ($("input[name=" + name + "]:checked").length) {
return true;
}
return $.uniform.i18n('req_radio', caption);
}
if ($field.is(':checkbox')) {
name = $field.attr('name');
if ($field.is(":checked")) { return true; }
return $.uniform.i18n('req_checkbox', caption);
}
Expand Down
20 changes: 20 additions & 0 deletions test/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,27 @@
$input.attr('data-default-value'),
"A default value of 100.00 should display with decimal point intact."
);
});

/**
* Case 17
*
* Support for input element names with a period
*
* @link https://github.com/LearningStation/uni-form/issues/issue/15
*/
test("Case 17: Support for input element names with a period", function() {
var $inputs = $('input[name="color"]'),
$form = $('#qunit-form');

$inputs.attr({
name: "demographicInfo.gender"
});

$form.uniform();
$form.submit();

ok($form.hasClass("failedSubmit"), "Required form failure");
});


Expand Down

0 comments on commit 8da1277

Please sign in to comment.