Skip to content

Commit

Permalink
Maintain an errors object with a list of all of the messages for the …
Browse files Browse the repository at this point in the history
…current form

This is sourced from
valmynd@7ed3865
This could have been fetched in a round about way with something like
$('#form-id div.ctrlHolder.error p.formHint') but this will be much more
convenient.
  • Loading branch information
LearningStation committed Aug 5, 2011
1 parent f1274dd commit d4426dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 20 additions & 3 deletions js/uni-form-validation.jquery.js
Expand Up @@ -30,6 +30,13 @@ jQuery.fn.uniform = function(extended_settings) {
*/
var self = this;

/**
* Errors of all fields by their names
*
* @var object
*/
var errors = {};

/**
* Object extending the defaults object
*
Expand Down Expand Up @@ -393,7 +400,7 @@ jQuery.fn.uniform = function(extended_settings) {
out = bits[0],
re = /^([ds])(.*)$/,
p;

for (var i=1; i<bits.length; i++) {
p = re.exec(bits[i]);
if (!p || arguments[i] === null) {
Expand Down Expand Up @@ -444,7 +451,7 @@ jQuery.fn.uniform = function(extended_settings) {

var showFormSuccess = function(form, title) {
var $message;

if ($('#okMsg').length) {
$('#okMsg').remove();
}
Expand Down Expand Up @@ -479,6 +486,16 @@ jQuery.fn.uniform = function(extended_settings) {
.toggleClass(settings.valid_class, valid)
.find('p.formHint');

// store this into the errors array, can be used by the custom callback
if (! valid) {
errors[name] = text;
}
else if (name in errors) {
delete errors[name];
}

// if the validation failed we'll stash the p help text into the info-data
// and then put the error message in it's place.
if (! valid && ! $p.data('info-text')) {
$p.data('info-text', $p.html());
}
Expand Down Expand Up @@ -688,7 +705,7 @@ jQuery.fn.uniform = function(extended_settings) {
form.delegate(settings.field_selector, 'success', function(e, text) {
validate($(this), true);
});

// Issue 9: HTML5 autofocus elements
// When the browser focuses, it happens before Uni-Form, and so we need
// the manually run the focus event here to deal with style changes
Expand Down
6 changes: 4 additions & 2 deletions js/uni-form-validation.jquery.min.js

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

0 comments on commit d4426dd

Please sign in to comment.