On Apr 26, 10:32 pm, rtconner <[EMAIL PROTECTED]> wrote:
> On Apr 26, 10:12 am, "R. Rajesh Jeba Anbiah"
> <[EMAIL PROTECTED]> wrote:
> > I'd like to know how to add the validation rule so that optional
> > fields will be validated only on entry. I'd thought that allowEmpty is
> > for that, but I seem to be wrong. Any help is appreciated. TIA
>
> allowEmpty is not the answer, but the answer *IS* in the thread below.
> Read it and use the tips from the people in there, and your problems
> shall be solved :)
>
> http://groups.google.com/group/cake-php/browse_thread/thread/2d5331603a513a27/339e4437b30405e7?lnk=gst&rnum=1#339e4437b30405e7

Thanks for your allowBlank patch <https://trac.cakephp.org/attachment/
ticket/2092/allowBlank.patch>

But, at least for me it needs patch again in model.php (see below
which is after my previous patch <https://trac.cakephp.org/ticket/
2359>)

FWIW, my usage of syntax is something outlined here <http://
groups.google.com/group/cake-php/msg/439dc65a6ddd80a9> and <http://
bin.cakephp.org/view/152660210>. If my previous patch and current
patch are not applied, it takes the default error message and other
option values (IOW, my custom error messages and options are not
taking effect).

In case, if it works for you without the patch, may I know your usage
(syntax) of validator? TIA

The patch is here, FYI:

Index: model.php

===================================================================

--- model.php   (revision 4887)

+++ model.php   (working copy)

@@ -1688,17 +1688,25 @@

                                'allowEmpty' => true,
                                'message' => 'This field cannot be left blank',
                                'rule' => 'blank',
-                               'on' => null
+                               'on' => null,
+                               'allowBlank' => false // patch for allowBlank 
(optional)
https://trac.cakephp.org/attachment/ticket/2092/allowBlank.patch
                        ), $validator);

                        if (isset($validator[0]['message'])) {  //weird fix
                                $validator['message'] = 
$validator[0]['message'];
                        }
+                       if (isset($validator[0]['allowBlank'])) {  //weird fix
+                               $validator['allowBlank'] = 
$validator[0]['allowBlank'];
+                       }
+                       if (isset($validator[0]['allowEmpty'])) {  //weird fix
+                               $validator['allowEmpty'] = 
$validator[0]['allowEmpty'];
+                       }

                        if (empty($validator['on']) || ($validator['on'] == 
'create' && !
$this->exists()) || ($validator['on'] == 'update' && $this->exists()))
{
                                if (empty($data[$fieldName]) && 
$validator['allowEmpty'] ==
false) {
                                        $this->invalidate($fieldName, 
$validator['message']);
                                } elseif (isset($data[$fieldName])) {
+                                       if ($validator['allowBlank'] === true &&
empty($data[$fieldName])) continue;
                                        if (is_array($validator['rule'])) {
                                                $rule = $validator['rule'][0];
                                                unset($validator['rule'][0]);


--
  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah.blogspot.com/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to