I think this is something is a fundamental feature that is missing on
1.1 forms.
I had to implement my i18n widget and hack the sfForm class to make
it work like the following:
class sfWidgetFormInputDecimal extends sfWidgetForm
{
/**
* Constructor.
*
* Available options:
*
* * type: The widget type (text by default)
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes =
array())
{
parent::configure($options,$attributes);
$this->addRequiredOption('culture');
$this->addOption('doNotConvertValues');
}
/**
* @param string $name The element name
* @param string $value The value displayed in this widget
* @param array $attributes An array of HTML attributes to be
merged with the default HTML attributes
* @param array $errors An array of errors for the field
*
* @return string An HTML tag string
*
* @see sfWidgetForm
*/
public function render($name, $value = null, $attributes = array(),
$errors = array())
{
if(!$this->getOption('doNotConvertValues')) {
$numberFormat = new sfNumberFormat($this->getOption('culture'));
$value = $numberFormat->format($value);
}
return $this->renderTag('input', array_merge(array('type' => $this-
>getOption('type'), 'name' => $name, 'value' => $value),
$attributes));
}
}
---------------------------------
hack on the sfForm (line 704)
see that I set the "doNotConvertValues" option to true when the form
is bound so that the widget will show exactly what the user had
typed.
* Returns the form field associated with the name (implements the
ArrayAccess interface).
*
* @param string $name The offset of the value to get
*
* @return sfFormField A form field instance
*/
public function offsetGet($name)
{
if (!isset($this->formFields[$name]))
{
if (!$widget = $this->widgetSchema[$name])
{
throw new InvalidArgumentException(sprintf('Widget "%s" does
not exist.', $name));
}
$values = $this->isBound ? $this->taintedValues : $this-
>defaults;
$class = $widget instanceof sfWidgetFormSchema ?
'sfFormFieldSchema' : 'sfFormField';
$this->formFields[$name] = new $class($widget, $this-
>getFormFieldSchema(), $name, isset($values[$name]) ? $values[$name] :
null, $this->errorSchema[$name]);
if($this->formFields[$name]->getWidget()-
>hasOption('doNotConvertValues')) {
if($this->isBound()) {
$this->formFields[$name]->getWidget()-
>setOption('doNotConvertValues',true);
}
}
}
return $this->formFields[$name];
}
On 14 out, 06:57, nico <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I'm just began sf. Thanx in advance for your help.
>
> I'm trying to repopulate my i18nformusing input_tag (i don't want to
> use widgets) but no matter what i can't manage to do it.
>
> i can create, update but if there is an error, the posted values are
> not in the field (the db value stays). Is it due to the i18n process
> or my misunderstanding of the framework ?
>
> MY TEMPLATE : editSuccess.php (i removed the unnecessary code)
> =========================================================
> <?php $category = $form->getObject() ; ?>
> <?php echo input_hidden_tag("category[id]" , $category->getId() ) ?>
>
> <?php $sf_user->setCulture($culture) ?>
> <?php echo $form[$culture]->renderError ( ) ; ?>
> <p>
> <?php echo label_for("category[".$culture."][category_name]" ,
> __("Category name") ) ?>
> // this one doesn't repopulate
> <?php echo input_tag("category[".$culture."]
> [category_name]" , $category->getCategoryName() ) ?>
> // this one doesn't work at all with a i18n model
> <?php echo object_input_tag( $category , "getCategoryName" )
> ?>
> </p>
> <?php echo input_hidden_tag("category[".$culture."][id]" , $category-
>
> >getId() ) ?>
>
> </form>
>
> MY ACTION
> ===========================================================
> public function executeEdit($request)
> {
> $this->culture = $this->getUser()->getCulture ( ) ;
> $this->form= new
> CategoryForm(CategoryPeer::retrieveByPk($request-
>
> >getParameter('id')));
>
> if ($request->isMethod('post'))
> {
> $this->form->bind($request->getParameter('category'));
> if ($this->form->isValid())
> {
> $category = $this->form->save();
> $this->redirect('category/index');
> }
> $this->title_h1 =
> $this->getContext()->getI18N()->__('The record
> has not been saved. Errors have occured');
> }else{
> $this->title_h1 =
> $this->getContext()->getI18N()->__('Edit this
> category');
> }
> }
>
> config/app.yml
> ===========================
> # default values
> all:
> cultures:
> enabled: [fr, en]
>
> application/config/settings.yml
> ===========================
> all:
> .settings:
> i18n: on
> default_culture: fr
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---