mirror of
https://github.com/myvesta/vesta
synced 2025-07-07 05:21:50 -07:00
Validation for no-spaces, a-zA-Z, emails added
This commit is contained in:
parent
f65b8c618b
commit
d5457b58d0
4 changed files with 80 additions and 10 deletions
|
@ -220,7 +220,7 @@ App.HTML.Build.user_form = function(options, id)
|
||||||
tpl.set(':save_button', 'SAVE');
|
tpl.set(':save_button', 'SAVE');
|
||||||
}
|
}
|
||||||
|
|
||||||
options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','NS':''};
|
options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':''};
|
||||||
|
|
||||||
tpl = App.HTML.setTplKeys(tpl, options, true);
|
tpl = App.HTML.setTplKeys(tpl, options, true);
|
||||||
tpl = App.HTML.Build.user_selects(tpl, options);
|
tpl = App.HTML.Build.user_selects(tpl, options);
|
||||||
|
|
|
@ -72,10 +72,11 @@ App.Model.add = function(values, source_json)
|
||||||
App.Helpers.Warn('Changes were not applied');
|
App.Helpers.Warn('Changes were not applied');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var build_method = App.Env.getWorldName() + '_entry';
|
/*var build_method = App.Env.getWorldName() + '_entry';
|
||||||
var tpl = App.HTML.Build[build_method](values, 'new');
|
var tpl = App.HTML.Build[build_method](values, 'new');
|
||||||
App.Ref.CONTENT..replaceWith(tpl);
|
App.Ref.CONTENT..replaceWith(tpl);*/
|
||||||
// todo: reply.data;
|
// todo: reply.data;
|
||||||
|
App.Pages.prepareHTML();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,11 +285,11 @@ App.Templates.html = {
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc">\
|
||||||
<label for="#" class="field-label">username:</label>\
|
<label for="#" class="field-label">username:</label>\
|
||||||
<input type="text" class="text-field" value="~!:LOGIN_NAME~!" name="LOGIN_NAME">\
|
<input type="text" class="text-field rule-abc rule-required" value="~!:LOGIN_NAME~!" name="LOGIN_NAME">\
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row pwd-box cc">\
|
<div class="form-row pwd-box cc">\
|
||||||
<label for="#" class="field-label">password:</label>\
|
<label for="#" class="field-label">password:</label>\
|
||||||
<input type="text" class="text-field password" name="PASSWORD" value="~!:PASSWORD~!">\
|
<input type="text" class="text-field password rule-required" name="PASSWORD" value="~!:PASSWORD~!">\
|
||||||
<span class="generate-pwd do_action_generate_pass">Generate</span>\
|
<span class="generate-pwd do_action_generate_pass">Generate</span>\
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc">\
|
||||||
|
@ -298,7 +298,7 @@ App.Templates.html = {
|
||||||
~!:PACKAGE_OPTIONS~!\
|
~!:PACKAGE_OPTIONS~!\
|
||||||
</select>\
|
</select>\
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc hidden">\
|
||||||
<label for="#" class="field-label">shell:</label>\
|
<label for="#" class="field-label">shell:</label>\
|
||||||
<select class="not-styled" name="SHELL">\
|
<select class="not-styled" name="SHELL">\
|
||||||
~!:SHELL_OPTIONS~!\
|
~!:SHELL_OPTIONS~!\
|
||||||
|
@ -312,13 +312,21 @@ App.Templates.html = {
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc">\
|
||||||
<label for="#" class="field-label">contact email:</label>\
|
<label for="#" class="field-label">contact email:</label>\
|
||||||
<input type="text" name="CONTACT" class="text-field" value="~!:CONTACT~!">\
|
<input type="text" name="CONTACT" class="text-field rule-email rule-required" value="~!:CONTACT~!">\
|
||||||
</div>\
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc">\
|
||||||
<label for="#" class="field-label">reports:</label>\
|
<label for="#" class="field-label">reports:</label>\
|
||||||
<input type="checkbox" name="REPORTS_ENABLED" class="not-styled" value="~!:REPORTS_ENABLED~!">\
|
<input type="checkbox" name="REPORTS_ENABLED" class="not-styled" value="~!:REPORTS_ENABLED~!">\
|
||||||
</div>\
|
</div>\
|
||||||
|
<div class="form-row cc">\
|
||||||
|
<label for="#" class="field-label">Firstname:</label>\
|
||||||
|
<input type="text" name="FNAME" class="not-styled rule-abc rule-required" value="~!:FNAME~!">\
|
||||||
|
</div>\
|
||||||
<div class="form-row cc">\
|
<div class="form-row cc">\
|
||||||
|
<label for="#" class="field-label">Lastname:</label>\
|
||||||
|
<input type="text" name="LNAME" class="not-styled rule-abc rule-required" value="~!:LNAME~!">\
|
||||||
|
</div>\
|
||||||
|
<div class="form-row cc hidden">\
|
||||||
<label for="#" class="field-label">ns1:</label>\
|
<label for="#" class="field-label">ns1:</label>\
|
||||||
<input type="text" name="NS" class="text-field" value="~!:NS~!">\
|
<input type="text" name="NS" class="text-field" value="~!:NS~!">\
|
||||||
</div>\
|
</div>\
|
||||||
|
@ -357,6 +365,7 @@ App.Templates.html = {
|
||||||
<div class="username-box">\
|
<div class="username-box">\
|
||||||
<span class="user">\
|
<span class="user">\
|
||||||
<span class="nickname do_action_edit">~!:LOGIN_NAME~!</span>\
|
<span class="nickname do_action_edit">~!:LOGIN_NAME~!</span>\
|
||||||
|
<span class="role">~!:FNAME~! ~!:LNAME~!</span>\
|
||||||
<span class="role">(~!:ROLE~!)</span>\
|
<span class="role">(~!:ROLE~!)</span>\
|
||||||
</span>\
|
</span>\
|
||||||
<span class="prop-box template-box">\
|
<span class="prop-box template-box">\
|
||||||
|
|
|
@ -13,6 +13,39 @@ App.Validate.Is = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
App.Validate.getFieldName = function(elm)
|
||||||
|
{
|
||||||
|
fb.log(elm);
|
||||||
|
fb.warn($(elm).prev('label').text());
|
||||||
|
return ['<strong>', $(elm).prev('label').text(), '</strong>'].join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
App.Validate.Rule = {
|
||||||
|
'required' : function(elm) {
|
||||||
|
if ($(elm).val().trim() == '') {
|
||||||
|
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is required'};
|
||||||
|
}
|
||||||
|
return {VALID: true};
|
||||||
|
},
|
||||||
|
'no-spaces': function(elm) {
|
||||||
|
if ($(elm).val().search(/\s/) != -1) {
|
||||||
|
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' cannot contain spaces'};
|
||||||
|
}
|
||||||
|
return {VALID: true};
|
||||||
|
},
|
||||||
|
'abc': function(elm) {
|
||||||
|
if ($(elm).val().search(/[^a-zA-Z]+/) != -1) {
|
||||||
|
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters'};
|
||||||
|
}
|
||||||
|
return {VALID: true};
|
||||||
|
},
|
||||||
|
'email': function(elm) {
|
||||||
|
if ($(elm).val().search(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/) == -1) {
|
||||||
|
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'};
|
||||||
|
}
|
||||||
|
return {VALID: true};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
App.Validate.form = function(world, elm)
|
App.Validate.form = function(world, elm)
|
||||||
|
@ -25,11 +58,23 @@ App.Validate.form = function(world, elm)
|
||||||
//return; // pass
|
//return; // pass
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var rules = App.Validate.getRules(field);
|
||||||
if ($(field).val().trim() == '' || $(field).val().trim() == '-') {
|
$(rules).each(function(i, rule)
|
||||||
|
{
|
||||||
|
fb.log('Validate with %o %o', rule, field);
|
||||||
|
if (App.Validate.Rule[rule]) {
|
||||||
|
var result = App.Validate.Rule[rule](field);
|
||||||
|
fb.log(result);
|
||||||
|
if (result.VALID == false) {
|
||||||
|
App.Env.FormError.push(result.ERROR); //$(field).attr('name') + ' is required');
|
||||||
|
form_valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
/*if ($(field).val().trim() == '' || $(field).val().trim() == '-') {
|
||||||
App.Env.FormError.push($(field).attr('name') + ' is required');
|
App.Env.FormError.push($(field).attr('name') + ' is required');
|
||||||
form_valid = false;
|
form_valid = false;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return form_valid;
|
return form_valid;
|
||||||
|
@ -49,5 +94,20 @@ App.Validate.displayFormErrors = function(world, elm)
|
||||||
ref.html(errors_tpl);
|
ref.html(errors_tpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.Validate.getRules = function(elm)
|
||||||
|
{
|
||||||
|
var rules_string = $(elm).attr('class');
|
||||||
|
var rules = [];
|
||||||
|
$(rules_string.split(/\s/)).each(function(i, str)
|
||||||
|
{
|
||||||
|
var rule = str.split('rule-');
|
||||||
|
if (rule.length > 1) {
|
||||||
|
rules[rules.length++] = rule[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue