Skip to content

Commit

Permalink
Dependent fields validation triggers configurability added + version up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaliszko committed Nov 28, 2014
1 parent c5419bc commit b72dab3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.3.0")]
[assembly: AssemblyFileVersion("2.2.3.0")]
[assembly: AssemblyVersion("2.2.4.0")]
[assembly: AssemblyFileVersion("2.2.4.0")]
2 changes: 2 additions & 0 deletions src/ExpressiveAnnotations.MvcWebSample/Views/Home/Home.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
// expann.addMethod... // do something with ExpressiveAnnotations
// ea... // do something with original ea variable
// ea.settings.dependencyTriggers = 'change'; // disable some excessive activity if you wish, and e.g. trigger dependent fields validation only when field "change" event is fired
@if ("pl" == lang)
{
<text>
Expand Down
20 changes: 11 additions & 9 deletions src/expressive.annotations.validate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* expressive.annotations.validate.js - v2.3.0
/* expressive.annotations.validate.js - v2.4.0
* Client-side component of ExpresiveAnnotations - annotation-based conditional validation library.
* https://github.com/JaroslawWaliszko/ExpressiveAnnotations
*
Expand All @@ -10,9 +10,11 @@ var
backup = window.ea, // map over the ea in case of overwrite

api = { // to be accesssed from outer scope
settings: {
parseObject: undefined, // if you'd like to represent a fields data in any other form than a default json (not recommended), it is the place for any custom deserializer
parseDate: undefined // provide implementation to parse date in non-standard format
settings: {
dependencyTriggers: 'change paste keyup', // a string containing one or more DOM field event types (such as "change", "keyup" or custom event names)
// for which fields directly dependent on referenced DOM field are validated
parseObject: undefined, // provide custom deserialization for objects when stored in non-json format
parseDate: undefined // provide custom parsing mechanism for dates when stored in non-standard format
// e.g., suppose DOM field date is given in dd/mm/yyyy format:
// parseDate = function(str) { // input string is given as a raw value extracted from DOM element
// var arr = str.split('/'); return new Date(arr[2], arr[1] - 1, arr[0]).getTime(); // return milliseconds since January 1, 1970, 00:00:00 UTC
Expand Down Expand Up @@ -385,17 +387,17 @@ var
if (referencedFields !== undefined && referencedFields !== null) {
i = referencedFields.length;
while (i--) {
field = $(form).find(':input[name="' + referencedFields[i] + '"]');
field = $(form).find(':input[data-val][name="' + referencedFields[i] + '"]');
if (field.length !== 0) {
field.valid();
}
}
}
},
binded: false,
bindAction: function(form) {
bindFields: function(form) {
if (!this.binded) {
$(form).find('input, select, textarea').bind('change paste keyup', function() {
$(form).find('input, select, textarea').bind(api.settings.dependencyTriggers, function() {
var field = $(this).attr('name');
validationHelper.validateReferences(field, form); // validate referenced fields only
});
Expand All @@ -420,7 +422,7 @@ var
options.messages[adapter] = options.message;
}
var rules = options.rules[adapter];
validationHelper.bindAction(options.form);
validationHelper.bindFields(options.form);
validationHelper.collectReferences(typeHelper.object.keys(rules.fieldsMap), options.element.name, rules.prefix);
});
});
Expand All @@ -440,7 +442,7 @@ var
options.messages[adapter] = options.message;
}
var rules = options.rules[adapter];
validationHelper.bindAction(options.form);
validationHelper.bindFields(options.form);
validationHelper.collectReferences(typeHelper.object.keys(rules.fieldsMap), options.element.name, rules.prefix);
});
});
Expand Down

0 comments on commit b72dab3

Please sign in to comment.