Re: [Freeipa-devel] [PATCH] admiyo-0134-Validate-add-dialog-text-fields

2011-01-07 Thread Endi Sukma Dewata

On 1/7/2011 11:15 PM, Adam Young wrote:

While this does not solve https://fedorahosted.org/freeipa/ticket/470,
it is a necessary precursor.


ACK and pushed to master.

--
Endi S. Dewata

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


[Freeipa-devel] [PATCH] admiyo-0134-Validate-add-dialog-text-fields

2011-01-07 Thread Adam Young
While this does not solve https://fedorahosted.org/freeipa/ticket/470, 
it is a necessary precursor.
From ef0cda4144bf1106db58dcca4923520c0094beab Mon Sep 17 00:00:00 2001
From: Adam Young 
Date: Fri, 7 Jan 2011 10:32:33 -0500
Subject: [PATCH] Validate add-dialog text fields

---
 install/static/widget.js |   71 --
 1 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/install/static/widget.js b/install/static/widget.js
index ed2ef8d5d5f2d10e6cdeca4bfb8fd7cab20e5301..f13a8b6e76f77dc8179812fc81921c8eed6218a3 100755
--- a/install/static/widget.js
+++ b/install/static/widget.js
@@ -43,6 +43,7 @@ function ipa_widget(spec) {
 that.load = spec.load || load;
 that.save = spec.save || save;
 that.update = spec.update || update;
+that.validate_input = spec.validate_input || validate_input;
 
 that.__defineGetter__("entity_name", function(){
 return that._entity_name;
@@ -52,9 +53,36 @@ function ipa_widget(spec) {
 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() {
 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)){
 that.label = param_info.label;
 }
@@ -113,6 +141,22 @@ function ipa_widget(spec) {
 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() {
 };
 
@@ -140,13 +184,18 @@ function ipa_text_widget(spec) {
 'size': that.size
 }).appendTo(container);
 
-if (that.undo) {
-$('', {
-'name': 'undo',
-'style': 'display: none;',
-'html': 'undo'
-}).appendTo(container);
-}
+$('', {
+'name': 'undo',
+'style': 'display: none;',
+'html': 'undo'
+}).appendTo(container);
+
+$("",{
+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) {
@@ -155,7 +204,11 @@ function ipa_text_widget(spec) {
 
 var input = $('input[name="'+that.name+'"]', that.container);
 input.keyup(function() {
-that.show_undo();
+if(that.undo){
+that.show_undo();
+}
+var value = $('input[name="'+that.name+'"]', that.container).val();
+that.validate_input(value);
 });
 
 var undo = that.get_undo();
-- 
1.7.3.4

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel