From f256b8857faff7627ba8b6a6df03b3b5cd294f91 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 26 Apr 2011 16:21:25 -0500 Subject: Entitlement quantity validation. The widget base class has been modified to validate integer value if the type is specified in the metadata. This is used to validate entitlement quantity. --- install/ui/dialog.js | 10 +++++- install/ui/dns.js | 2 +- install/ui/entitle.js | 12 +++++-- install/ui/host.js | 2 +- install/ui/ipa.js | 23 +++++++++++++- install/ui/service.js | 4 +-- install/ui/widget.js | 86 ++++++++++++++++++++++++++++++++++----------------- 7 files changed, 101 insertions(+), 38 deletions(-) diff --git a/install/ui/dialog.js b/install/ui/dialog.js index f60db5ca..2c9fdb0e 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -74,11 +74,19 @@ IPA.dialog = function(spec) { that.fields_by_name[field.name] = field; }; - that.field = function(field){ + that.field = function(field) { that.add_field(field); return that; }; + that.is_valid = function() { + for (var i=0; i that.metadata.maxvalue) { + that.valid = false; + // TODO: I18n + that.show_error('maximum value is '+that.metadata.maxvalue); + return; + } } - that.valid = false; } - } + + if (that.param_info) { + if (that.param_info.pattern) { + var regex = new RegExp(that.param_info.pattern); + if (!value.match(regex)) { + that.valid = false; + that.show_error(that.param_info.pattern_errmsg); + return; + } + } + } + }; function init() { if (that.entity_name) { @@ -247,12 +278,13 @@ IPA.widget = function(spec) { return $('span[name="error_link"]', that.container); }; - that.show_error_link = function() { + that.show_error = function(message) { var error_link = that.get_error_link(); - error_link.css('display', 'inline'); + error_link.html(message); + error_link.css('display', 'block'); }; - that.hide_error_link = function() { + that.hide_error = function() { var error_link = that.get_error_link(); error_link.css('display', 'none'); }; @@ -323,8 +355,7 @@ IPA.text_widget = function(spec) { if (that.undo) { that.show_undo(); } - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); var undo = that.get_undo(); @@ -539,8 +570,7 @@ IPA.multivalued_text_widget = function(spec) { remove_link.css('display', 'inline'); } } - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); remove_link.click(function() { @@ -965,9 +995,7 @@ IPA.textarea_widget = function (spec) { var input = $('textarea[name="'+that.name+'"]', that.container); input.keyup(function() { that.show_undo(); - - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); -- cgit