mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Validate add-dialog text fields
This commit is contained in:
parent
aea1bc7959
commit
5c9c006af1
@ -43,6 +43,7 @@ function ipa_widget(spec) {
|
|||||||
that.load = spec.load || load;
|
that.load = spec.load || load;
|
||||||
that.save = spec.save || save;
|
that.save = spec.save || save;
|
||||||
that.update = spec.update || update;
|
that.update = spec.update || update;
|
||||||
|
that.validate_input = spec.validate_input || validate_input;
|
||||||
|
|
||||||
that.__defineGetter__("entity_name", function(){
|
that.__defineGetter__("entity_name", function(){
|
||||||
return that._entity_name;
|
return that._entity_name;
|
||||||
@ -52,9 +53,36 @@ function ipa_widget(spec) {
|
|||||||
that._entity_name = entity_name;
|
that._entity_name = entity_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var param_info;
|
||||||
|
|
||||||
|
/*returns true and clears the error message if the field value passes
|
||||||
|
the validation pattern. If the field value does not pass validation,
|
||||||
|
displays the error message and returns false. */
|
||||||
|
function validate_input(text){
|
||||||
|
if(!(param_info && param_info.pattern)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var error_link = that.get_error_link();
|
||||||
|
if (!error_link){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var regex = new RegExp( param_info.pattern );
|
||||||
|
//If the field is empty, don't validate
|
||||||
|
if (!text || text.match(regex) ) {
|
||||||
|
error_link.css('display', 'none');
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
error_link.css('display', 'block');
|
||||||
|
if ( param_info.pattern_errmsg){
|
||||||
|
error_link.html(param_info.pattern_errmsg);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (that.entity_name && !that.label){
|
if (that.entity_name && !that.label){
|
||||||
var param_info = ipa_get_param_info(that.entity_name, spec.name);
|
param_info = ipa_get_param_info(that.entity_name, spec.name);
|
||||||
if ((param_info) && (that.label === undefined)){
|
if ((param_info) && (that.label === undefined)){
|
||||||
that.label = param_info.label;
|
that.label = param_info.label;
|
||||||
}
|
}
|
||||||
@ -113,6 +141,22 @@ function ipa_widget(spec) {
|
|||||||
undo.css('display', 'none');
|
undo.css('display', 'none');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.get_error_link = function() {
|
||||||
|
return $('span[name="error_link"]', that.container);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.show_error_link = function() {
|
||||||
|
var error_link = that.get_error_link();
|
||||||
|
error_link.css('display', 'inline');
|
||||||
|
};
|
||||||
|
|
||||||
|
that.hide_error_link = function() {
|
||||||
|
var error_link = that.get_error_link();
|
||||||
|
error_link.css('display', 'none');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
that.refresh = function() {
|
that.refresh = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -140,13 +184,18 @@ function ipa_text_widget(spec) {
|
|||||||
'size': that.size
|
'size': that.size
|
||||||
}).appendTo(container);
|
}).appendTo(container);
|
||||||
|
|
||||||
if (that.undo) {
|
|
||||||
$('<span/>', {
|
$('<span/>', {
|
||||||
'name': 'undo',
|
'name': 'undo',
|
||||||
'style': 'display: none;',
|
'style': 'display: none;',
|
||||||
'html': 'undo'
|
'html': 'undo'
|
||||||
}).appendTo(container);
|
}).appendTo(container);
|
||||||
}
|
|
||||||
|
$("<span/>",{
|
||||||
|
name:'error_link',
|
||||||
|
html:"Text does not match field pattern",
|
||||||
|
"class":"ui-state-error ui-corner-all",
|
||||||
|
style:"display:none"
|
||||||
|
}).appendTo(container);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setup = function(container) {
|
that.setup = function(container) {
|
||||||
@ -155,7 +204,11 @@ function ipa_text_widget(spec) {
|
|||||||
|
|
||||||
var input = $('input[name="'+that.name+'"]', that.container);
|
var input = $('input[name="'+that.name+'"]', that.container);
|
||||||
input.keyup(function() {
|
input.keyup(function() {
|
||||||
|
if(that.undo){
|
||||||
that.show_undo();
|
that.show_undo();
|
||||||
|
}
|
||||||
|
var value = $('input[name="'+that.name+'"]', that.container).val();
|
||||||
|
that.validate_input(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
var undo = that.get_undo();
|
var undo = that.get_undo();
|
||||||
|
Loading…
Reference in New Issue
Block a user