[claw-cvs] r162 - trunk/main/claw-html/src

Andrea Chiumenti achiumenti at common-lisp.net
Fri Dec 19 12:55:00 UTC 2008


Author: achiumenti
Date: Fri Dec 19 12:54:59 2008
New Revision: 162

Log:
validation bugfix

Modified:
   trunk/main/claw-html/src/components.lisp
   trunk/main/claw-html/src/validators.lisp

Modified: trunk/main/claw-html/src/components.lisp
==============================================================================
--- trunk/main/claw-html/src/components.lisp	(original)
+++ trunk/main/claw-html/src/components.lisp	Fri Dec 19 12:54:59 2008
@@ -302,7 +302,7 @@
           (value (translated-value cinput)))
       (unless (or (null value) (null visit-object) (component-validation-errors cinput))
 	(when validator
-	  (funcall validator cinput))
+	  (funcall validator value))
 	(unless (component-validation-errors cinput)
 	  (if (and (null writer) accessor)
 	      (funcall (fdefinition `(setf ,accessor)) (if (and (stringp value) (string= value "") (base-cinput-empty-to-null-p cinput))

Modified: trunk/main/claw-html/src/validators.lisp
==============================================================================
--- trunk/main/claw-html/src/validators.lisp	(original)
+++ trunk/main/claw-html/src/validators.lisp	Fri Dec 19 12:54:59 2008
@@ -70,15 +70,17 @@
         (add-validation-compliance client-id)
         (add-validation-error client-id message))))
 
-(defun validate-required (component value &key message component-label)
+(defun validate-required (value &key (component (page-current-component *claw-current-page*)) message component-label)
   "Checks if the required input field VALUE is present.  If not, a localizable message \"Field ~a may not be empty.\" is sent with key \"VALIDATE-REQUIRED\".
 The argument for the message will be the :label attribute of the COMPONENT."
+  (unless value
+    (setf value ""))
   (when (stringp value)
     (validate (and value (string-not-equal value ""))
               :component component
               :message (or message (format nil "Field ~a may not be empty." (or component-label (label component)))))))
 
-(defun validate-size (component value &key min-size max-size message-low message-hi component-label)
+(defun validate-size (value &key (component (page-current-component *claw-current-page*)) min-size max-size message-low message-hi component-label)
   "Checks if the input field VALUE legth is less then or greater then rispectively of the form keywords :MIN-SIZE and :MAX-SIZE.
 If less then :MIN-SIZE, a localizable message \"Size of ~a may not be less then ~a chars.\" is sent with key \"VALIDATE-SIZE-MIN\".
 The argument for the message will be the :label attribute of the COMPONENT and the :MIN-ZIZE value.
@@ -102,7 +104,7 @@
                                                        (or component-label (label component))
                                                        max-size))))))))
 
-(defun validate-range (component value &key min max message-low message-hi component-label)
+(defun validate-range (value &key (component (page-current-component *claw-current-page*)) min max message-low message-hi component-label)
   "Checks if the numeric input field VALUE is less then or greater then rispectively of the form keywords :MIN and :MAX.
 If less then :MIN, a localizable message \"Field ~a is not less then or equal to ~d.\" is sent with key \"VALIDATE-RANGE-MIN\".
 The argument for the message will be the :label attribute of the COMPONENT and the :MIN value.
@@ -126,7 +128,7 @@
                                                          (coerce max 'float)
                                                          max))))))))
 
-(defun validate-number (component value &key min max message-nan message-low message-hi component-label)
+(defun validate-number (value &key (component (page-current-component *claw-current-page*)) min max message-nan message-low message-hi component-label)
   "Checks if the input field VALUE is a valid number and then passes the validation to VALIDATION-RANGE.
 If not a number, a localizable message \"Field ~a is not a valid number.\" is sent with key \"VALIDATE-NUMBER\".
 The argument for the message will be the :label attribute of the COMPONENT."
@@ -136,9 +138,9 @@
                      :component component
                      :message (or message-nan (format nil "Field ~a is not a valid number." (or component-label
                                                                                                 (label component)))))
-           (validate-range component value :min min :max max :message-low  message-low :message-hi message-hi :component-label component-label)))))
+           (validate-range value :component component :min min :max max :message-low  message-low :message-hi message-hi :component-label component-label)))))
 
-(defun validate-integer (component value &key min max message-nan message-low message-hi component-label)
+(defun validate-integer (value &key (component (page-current-component *claw-current-page*)) min max message-nan message-low message-hi component-label)
   "Checks if the input field VALUE is a valid number and then passes the validation to VALIDATION-RANGE.
 If not a number, a localizable message \"Field ~a is not a valid integer.\" is sent with key \"VALIDATE-INTEGER\".
 The argument for the message will be the :label attribute of the COMPONENT."
@@ -147,10 +149,10 @@
       (and (validate test
                      :component component
                      :message (or message-nan (format nil "Field ~a is not a valid integer." (or component-label (label component)))))
-           (validate-range component value :min min :max max :message-low  message-low :message-hi message-hi :component-label component-label)))))
+           (validate-range value :component component :min min :max max :message-low  message-low :message-hi message-hi :component-label component-label)))))
 
 
-(defun validate-date-range (component value &key min max (use-date-p t) use-time-p message-low message-hi component-label)
+(defun validate-date-range (value &key (component (page-current-component *claw-current-page*)) min max (use-date-p t) use-time-p message-low message-hi component-label)
   "Checks if the input field VALUE is a date between min and max.
 If :USE-DATE-P is not nil and :USE-TIME-P is nil, validation is made without considering the time part of local-time.
 If :USE-DATE-P nil and :USE-TIME-P is not nil, validation is made without considering the date part of local-time.
@@ -159,7 +161,6 @@
 The argument for the message will be the :label attribute of the COMPONENT and the value passed to :MIN parsed with the :LOCAL-TIME-FORMAT keyword.
 If value is greater then the date passed to :MAX, a localizable message \"Field ~a is greater then ~a.\" is sent with key \"VALIDATE-DATE-RANGE-MAX\".
 The argument for the message will be the :label attribute of the COMPONENT and the value passed to :MAX parsed with the :LOCAL-TIME-FORMAT keyword."
-;  (unless (component-validation-errors component))
   (let ((local-time-format '(:date "-" :month "-" :year))
         (new-value (make-instance 'local-time
                                   :nsec (nsec-of value)




More information about the Claw-cvs mailing list