Symfony widgeteket fogok ide kirakni, néhol egy icipici kis magyarázattal.

datePicker:

[php]
class datePickerWidget extends sfWidgetFormInput
{

public function configure($options = array(), $attributes = array())
{
$this->addOption(‘ifFormat’, "%Y-%m-%d");
parent::configure($options, $attributes);
}

public function render($name, $value = null, $attributes = array(), $errors = array())
{
use_helper(‘Javascript’, ‘wtCurrency’);
$response = sfContext::getInstance()->getResponse();
$response->addStylesheet(‘/sf/calendar/calendar-system.css’);
$response->addJavascript(‘/sf/calendar/calendar.js’);
$response->addJavascript(‘/sf/calendar/lang/calendar-en.js’);
$response->addJavascript(‘/sf/calendar/calendar-setup.js’);
$response->addJavascript(sfConfig::get(‘sf_prototype_web_dir’).’/js/prototype’);

$picker = javascript_tag("
Calendar.setup(
{
inputField : ‘".$this->generateId($name)."’,
ifFormat : ‘".$this->getOption(‘ifFormat’)."’,
button : ‘trigger’, // ID of the button
})
");
return parent::render($name, $value, $attributes, $errors) . $picker;
}
}
[/php]

Autocompliter:
innen az eredeti

[php]
class sfExtraWidgetFormInputAutocomplete extends sfWidgetFormInput
{
public function configure($options = array(), $attributes = array())
{
$this->addRequiredOption(‘url’);
$this->addOption(‘param’, ‘autocomplete’);
$this->addOption(‘min_chars’, 2);
$this->addOption(‘afterUpdateElement’,”);
parent::configure($options, $attributes);
}

public function render($name, $value = null, $attributes = array(), $errors = array())
{
$response = sfContext::getInstance()->getResponse();
$response->addJavascript(sfConfig::get(‘sf_prototype_web_dir’).’/js/prototype’);
$response->addJavascript(sfConfig::get(‘sf_prototype_web_dir’).’/js/scriptaculous.js’);
sfLoader::loadHelpers(array(‘Javascript’));
$response->addStylesheet(‘/sfExtraWidgetsPlugin/css/autocompleter.css’);

$autocompleteDiv = content_tag(‘div’ , ”, array(‘id’ => $this->generateId($name) . ‘_autocomplete’, ‘class’ => ‘autocomplete’));

$autocompleteJs = javascript_tag(
"function ac_update_" . $this->generateId($name) . "(text, li)
{
$(‘" . $this->generateId($name) . "’).value = li.innerHTML;
".$this->getOption(‘afterUpdateElement’)."
}

new Ajax.Autocompleter(
‘" . $this->generateId($name) . "’,
‘" . $this->generateId($name) . ‘_autocomplete’ . "’,
‘" . url_for($this->getOption(‘url’)) . "’,
{
paramName: ‘" . $this->getOption(‘param’) . "’,
indicator: ‘indicator-" . $this->generateId($name) . "’,
minChars: " . $this->getOption(‘min_chars’) . ",
afterUpdateElement: ac_update_" . $this->generateId($name) . "
});"
);

return parent::render($name, $value, $attributes, $errors) .
‘<span id="indicator-‘ . $this->generateId($name) . ‘" style="display: none;">&nbsp;&nbsp;<img src="/sfExtraWidgetsPlugin/img/ajax-loader.gif" align="absmiddle" alt="Loading" /></span>’ .
$autocompleteDiv .
$autocompleteJs;
}
}
[/php]

használata:
widget:

[php]
$this->widgetSchema[‘nevsearch’] = new sfExtraWidgetFormInputAutocomplete(array(
‘url’=>’modul/action’,
‘afterUpdateElement’=>’afterUpdateElement_nevsearch(text, li)’));
// ezt a javascript függvényt létre kell hozni.
//vagy egyszerűen az eredti módszerrel:
$this->widgetSchema[‘projekt’] = new sfExtraWidgetFormInputAutocomplete(array(‘url’=>’modul/action’));
[/php]

actionSuccess.php

[php]
<ul>
<?php foreach ($words as $value):?>
<li id='<?php echo $value?>’><?php echo $value?></li>
<?php endforeach?>
</ul>
[/php]

checkbox

[php]$this->widgetSchema[‘checkbox’] = new sfWidgetFormInputCheckbox();
$this->validatorSchema[‘checkbox’] = new sfValidatorPass();[/php]

checkbox rejtett false értékkel
A’ la cakephp. A lényeg hogy vizsgálhassuk a mező értékét, mert a symfonyban alapból nem jön semmi a post adatokkal, ha a checkbox nincs kiválasztva…

[php]
class sfWidgetFormInputCheckboxExtend extends sfWidgetFormInputCheckbox
{
public function render($name, $value = null, $attributes = array(), $errors = array())
{
$hidden = new sfWidgetFormInputHidden();
$hidden = $hidden->render($name, 0, array(‘id’=>false));

$value = ($value == 0) ? null : $value;
$attributes[‘value’] = 1;

return $hidden.parent::render($name, $value, $attributes, $errors);
}
}
[/php]