On 16 Sty, 13:35, Thomas Dedericks <[email protected]> wrote:
> Hi,
>
> Not tested:
>
> public function configure() {
>
>         ...
>
>         # add * torequiredfields' labels:
>         foreach ($this->widgetSchema as $name => $widget)
>         {
>                 if (isset($this->validatorSchema[$name]) && 
> $this->validatorSchema[$name]->hasOption('required') && 
> $this->validatorSchema[$name]->getOption('required') == true)
>                 {
>                         $label = ($widget->getLabel() != null) ? 
> $widget->getLabel() : $name;
>                         $widget->setLabel($label.' *');
>                 }
>         }
>
> }
>
> Thomas Dedericks

Unfortunatelly it doesn't work. But if you do some stuff before and
with little change...it works :)
1. Required option is true as default. I don't know why it isn't set
in widgetSchema. So this won't work: $this->validatorSchema[$name]-
>hasOption('required') && $this->validatorSchema[$name]->getOption
('required') == true
2. If label is set in generator.yml, it isn't  set in widgetSchema, so
$widget->getLabel() != null is always null You have to set it manually
in configure()
3. widgetSchema i a set of objects, not name fields, so you have to
add this:   foreach ($this->widgetSchema->getFields() as $name =>
$widget)

So you have to set labels for requried fields in configure() of a form
and for some fields, like boolean you have to add manually required to
true, like this: $this->validatorSchema['master'] = new
sfValidatorBoolean(array('required' => true)); And also change this:
&& $this->validatorSchema[$name]->getOption('required') != false).....
required != false

    foreach ($this->widgetSchema->getFields() as $name => $widget)
    {
      if (isset($this->validatorSchema[$name]) && $this-
>validatorSchema[$name]->hasOption('required') && $this-
>validatorSchema[$name]->getOption('required') != false)
      {
        $label = ($widget->getLabel() != null) ? $widget->getLabel() :
$name;
        $widget->setLabel($label.' *');
      }
    }

All in all it is faster just to add * manually for required fields:
    $this->widgetSchema->setLabels(array(
        'logo' => 'Logo *',
        'name' => 'Name *',
        'master' => 'Master *',
    ));
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" 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/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to