Thank you for explaining how Zend_Form is supposed to work. I do better understand the meaning of "default value" in this context, but...

...the context where I use it is slightly different than a plain old HTML form. 
Let me explain.

The posted data come from an XHR sent by a dojox.data.JsonRestStore. (The user is able to create/edit items directly in the grid.) But the grid represents only a subset of the item properties as its width is limited. As a consequence, not all required form elements are sent by the XHR. This is not a problem for updates as I can use isValidPartial(). But for inserts, I need to complete the posted data with default values: that's why I try to use setDefault().

Le 11/08/10 01:01, Hector Virgen a écrit :
I'm not sure if that's how the "default" value is supposed to work. AFAIK, it 
sets the default value
for the form element when the page is loaded. The user can then overwrite this 
value by editing the
field. If the user empties the field, then I consider that a deliberate attempt 
to submit an empty
string for that field.

Btw, why doesn't that element appear in the post data?

--
Hector Virgen
Sent on my Droid X

On Aug 10, 2010 3:50 PM, "Guillaume ORIOL" <[email protected] 
<mailto:[email protected]>> wrote:

No, this is not a hidden field.
I already tried your suggestion with setValue() but it doesn't help.

I was able to trace my problem down to the Zend_Form::isValid() method. For 
each element, this
code block is executed:

           if (!isset($check[$key])) {
               $valid = $element->isValid(null, $context) && $valid;
           } else {
               $valid = $element->isValid($check[$key], $context) && $valid;
               $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key);
           }

As you can see, the element is not validated against its (default) value when 
the value doesn't
exist in the posted data.

Le 11/08/10 00:42, Hector Virgen a écrit :

    >
    > Is it a hidden input? Try this to see if it helps:
    >
    > $form->getElement('nature')->setValue('co...

        >> On Aug 10, 2010 3:38 PM, "Guillaume ORIOL" <[email protected]
        <mailto:[email protected]> <mailto:[email protected] 
<mailto:[email protected]>>>
        w...

        <mailto:[email protected] <mailto:[email protected]>> 
<mailto:[email protected]
        <mailto:[email protected]> <mailto:[email protected]
        <mailto:[email protected]>>>> w...

Reply via email to