Actually, the example I thought of was done with two separate widgets. But I 
found another, a form where the user can enter measurements in a choice of 
units (inches or centimeters). The etWidgetFormJQuerySliderWithUnits widget 
renders a jQuery UI slider. The unit widget is used over several measurements. 
If one unit select is changed, all others and all entered values are changed 
with JavaScript.
I declare the unit widget as sfWidgetFormSelect and then include it in the 
other widgets as an option. Its default value is another option:

$this->setWidget( 'units', new sfWidgetFormSelect( array( 'choices' => 
sfConfig::get( 'app_lookup_units' ) ) );
$this->setWidget( 'neck_girth', new etWidgetFormJQuerySliderWithUnits( array( 
'min' => 200, 'max' => 500, 'step' => 5, 'units' => 
$this->widgetSchema['units'], 'unit' => 10 ) ) );
$this->setWidget( 'head_girth', new etWidgetFormJQuerySliderWithUnits( array( 
'min' => 200, 'max' => 500, 'step' => 5, 'units' => 
$this->widgetSchema['units'], 'unit' => 10 ) ) );

in updateDefaultsFromObject(), the default unit can be set:

if ( isset( $this->widgetSchema['neck_girth'] ) )
{
  $this->widgetSchema['neck_girth']->setOption( 'unit', 
$this->object->getUnit() );
}

The bind / clean process does not affect the included widget, so its value must 
be collected in updateObject():

if ( array_key_exists( 'neck_girth', $values['units'] ) )
{
  $this->object->setUnit( $values['units']['neck_girth'] );
}

can't send you the link because the site is not yet live. The solution works, 
but I found it rather cumbersome, I wouldn't do this if it wasn't for the 
interface interactivity.

Stefan

On Feb 3, 2010, at 3:40 PM, Stephen Melrose wrote:

> I thought a custom widget would be the way to go. However, I've never
> made one with multiple fields within it. Can you give me/link me to an
> example of how to do this?
> 
> Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-us...@googlegroups.com.
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en.

Reply via email to