Or why don't you create a formatter for the form that adds an asterisk
to all labels?
On 07/16/2010 05:54 PM, Daniel Lohse wrote:
What do you mean by "I don't have the form as reference"? Look at the
ahDoctrineEasyEmbeddedRelationsPlugin and search for "form.post_configure". Although the
callback is inside the form itself, I am using the event subject, so don't let that throw you off.
:)
Cheers, Daniel
Sent from my iPhone
On Jul 16, 2010, at 5:43 PM, Robert Schoenthal<[email protected]> wrote:
He Folks,
is it possible to manipulate a form with events?
I want to mark all labels as required, i think this is a very common
task. i tried to do it as central as it could be, therefore im willing
to use the sfEventDispatcher...
here is my approach:
class ProjectConfiguration extends sfProjectConfiguration
{
/**
* setup the symfony system
*/
public function setup()
{
$this->registerEvents();
}
/**
* register all events
*/
protected function registerEvents()
{
$this->dispatcher->connect('form.post_configure',
array('BaseForm', 'markLabelsRequired'));
}
}
<?php
class BaseForm extends sfFormSymfony
{
/**
* marks all labels as required
*/
public static function markLabelsRequired(sfEvent $event)
{
$frm = $event->getSubject();
/* @var sfForm $frm */
foreach($frm->getFormFieldSchema()->getWidget()->getFields() as
$key => $object)
{
$label = $frm->getFormFieldSchema()->offsetGet($key)-
renderLabelName();
if($frm->getValidatorSchema()->offsetGet($key)&& $frm-
getValidatorSchema()->offsetGet($key)->getOption('required') == true)
{
$frm->getWidgetSchema()->setLabel($key,'<span
class="required">'.$label.'</span>');
}
}
}
}
But, what a wonder a wont work, cause i dont have the form as
reference :( how could it be done in another way? through the
sfForm::configure cascade, it doesnt works as expected (depending on
where to call it), in a deep inheritance system, its nearly
impossible. the event approach is the finest i could think of, but how
can a manipulate the form within an event?
maybe someone could help?
cheerz
robert
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
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
--
Javi
Ubuntu 8.04 - Symfony 1.3
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
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