On 07/06/2011 03:44 PM, Adam Young wrote:



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

From d6148920eb1b079e935162e930c81fb66c6cdaa6 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Wed, 6 Jul 2011 15:43:50 -0400
Subject: [PATCH] check required on blur

previsouly was checked on key down, but that does the check too soon.
works for entity_select widget, too

https://fedorahosted.org/freeipa/ticket/1437
---
 install/ui/widget.js |   64 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/install/ui/widget.js b/install/ui/widget.js
index cd3a5c60e2153b25c0fce58ebaf94cf3f51f1ffe..d8458150918e69f17fbd322365d48cad0fe03baa 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -107,27 +107,37 @@ IPA.widget = function(spec) {
         }
 
     }
+    that.create_error_link = function(container){
+        container.append(' ');
+
+        $('<span/>', {
+            name: 'error_link',
+            html: IPA.messages.widget.validation.error,
+            'class': 'ui-state-error ui-corner-all',
+            style: 'display:none'
+        }).appendTo(container);
+    }
+
+    that.check_required = function(){
+        var values = that.save();
+        if (!values || !values.length || values[0] === '' ) {
+            if (that.param_info &&
+                that.param_info.required &&
+                !that.optional) {
+                that.valid = false;
+                that.show_error(IPA.messages.widget.validation.required);
+            }
+        }
+    };
 
     /*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. */
     that.validate = function() {
-
         that.hide_error();
-
         that.valid = true;
 
         var values = that.save();
-        if (!values || !values.length) {
-            if (that.param_info &&
-                that.param_info.required &&
-                !that.optional) {
-                that.valid = false;
-                that.show_error(IPA.messages.widget.validation.required);
-            }
-            return;
-        }
-
         var value = values[0];
         if (!value) {
             return;
@@ -371,6 +381,7 @@ IPA.text_widget = function(spec) {
         IPA.select_range(that.input, start, end);
     };
 
+
     that.create = function(container) {
 
         $('<label/>', {
@@ -391,14 +402,7 @@ IPA.text_widget = function(spec) {
             that.create_undo(container);
         }
 
-        container.append(' ');
-
-        $('<span/>', {
-            name: 'error_link',
-            html: IPA.messages.widget.validation.error,
-            'class': 'ui-state-error ui-corner-all',
-            style: 'display:none'
-        }).appendTo(container);
+        that.create_error_link(container);
     };
 
     that.setup = function(container) {
@@ -411,6 +415,10 @@ IPA.text_widget = function(spec) {
             that.validate();
         });
 
+        input.blur(function(){
+            that.check_required();
+        });
+
         var undo = that.get_undo();
         undo.click(function() {
             that.reset();
@@ -1098,6 +1106,10 @@ IPA.textarea_widget = function (spec) {
 
         });
 
+        input.blur(function(){
+            that.check_required();
+        });
+
         var undo = that.get_undo();
         undo.click(function() {
             that.reset();
@@ -1649,12 +1661,21 @@ IPA.entity_select_widget = function(spec) {
         if (editable){
             that.edit_box = $('<input />',{
                 type: 'text',
-                title: that.tooltip
+                title: that.tooltip,
+                blur:function(){
+                    that.check_required();
+                },
+                keyup:function(){
+                    that.hide_error();
+                }
             });
 
             $('<div style:"display=block;" />').
                 append(that.edit_box).
                 appendTo(container);
+
+            that.create_error_link(container);
+
         }
 
         that.entity_select = $('<select/>', {
@@ -1664,6 +1685,7 @@ IPA.entity_select_widget = function(spec) {
                     that.edit_box.val(
                         $('option:selected', that.entity_select).val());
                     IPA.select_range(that.edit_box,0,0);
+                    that.hide_error();
                 }
                 that.set_dirty(that.test_dirty());
             }
-- 
1.7.5.2

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

Reply via email to