Permalink
Browse files

Escape the name when looking for required radio buttons. Fixes Issue #17



* 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 8da127704258d69ca7d942c557c4e88bd1d66e35
View
@@ -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 %>',
@@ -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']);
@@ -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 */
//
@@ -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);
@@ -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);
}

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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 */
//

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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);
View
@@ -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);
}
View
@@ -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");
});

0 comments on commit 8da1277

Please sign in to comment.