1
0
Fork 0

added functionality to validate modals content

This commit is contained in:
Heiko Kernbach 2014-08-12 15:11:14 +02:00
parent 3322b3c4f9
commit 039f7884aa
4 changed files with 7254 additions and 8 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
/*global _, Backbone, templateEngine, window, setTimeout, clearTimeout, arangoHelper, $*/
/*global _, Backbone, templateEngine, window, setTimeout, clearTimeout, arangoHelper, Joi, $*/
(function() {
"use strict";
@ -298,7 +298,21 @@
"",
false,
"",
true
true,
[
{
rule: Joi.string().required(),
msg: "No collection name given."
},
// {
// rule: Joi.string().regex(),
// msg: "Only the symbols '_' and '-' are allowed."
// },
{
rule: Joi.string().regex(/^[a-zA-Z]/),
msg: "Collection name must always start with a letter."
}
]
)
);
tableContent.push(
@ -347,7 +361,17 @@
"",
"The maximal size of a journal or datafile (in MB). Must be at least 1.",
"",
false
false,
[
{
rule: Joi.string().regex(/[0-9]+/),
msg: "Only numbers allowed."
},
{
rule: Joi.string().min(1),
msg: "Must be at least 1."
}
]
)
);
advancedTableContent.push(

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
/*global Backbone, $, window, setTimeout, _ */
/*global Backbone, $, window, setTimeout, Joi, _ */
/*global templateEngine*/
(function () {
@ -46,7 +46,8 @@
if (regexp){
// returns true if the string contains the match
obj.validateInput = function(el){
return regexp.test(el.val());
//return regexp.test(el.val());
return regexp;
};
}
return obj;
@ -299,12 +300,54 @@
self.testInput = (function(){
_.each(tableContent,function(r){
if(r.validateInput){
if(r.validateInput) {
//catch result of validation and act
$('#' + r.id).on('keyup', function(){
if(r.validateInput($('#' + r.id))){
var validation = r.validateInput($('#' + r.id));
var error = false, msg;
_.each(validation, function(validator, key) {
var schema = Joi.object().keys({
toCheck: validator.rule
});
Joi.validate({
toCheck: $('#' + r.id).val()
},
schema,
function (err, value) {
if (err) {
msg = validator.msg;
error = true;
}
});
});
var errorElement = $('#'+r.id).next()[0];
if(error === true){
// if validation throws an error
$('#' + r.id).addClass('invalid-input');
} else {
if (errorElement) {
//error element available
$(errorElement).text(msg);
}
else {
//render error element
$('#' + r.id).after('<p class="errorMessage">' + msg+ '</p>');
}
}
else {
//validation throws success
$('#' + r.id).removeClass('invalid-input');
if (errorElement) {
$(errorElement).remove();
}
}
});
}

View File

@ -202,6 +202,7 @@
"frontend/js/lib/swagger.js",
"frontend/js/lib/swagger-ui.js",
"frontend/js/lib/highlight.7.3.pack.js",
"frontend/js/lib/joi.browser.js",
"frontend/js/lib/md5.js"
]
},