Development

#1342 (radio buttons not checked with fillin enabled)

You must first sign up to be able to contribute.

Ticket #1342 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

radio buttons not checked with fillin enabled

Reported by: roga.moore Assigned to:
Priority: minor Milestone:
Component: Version: 1.0.0-beta2
Keywords: Cc:
Qualification:

Description

I cannot get the sfFillInForm filter to work with radio buttons in the current beta.

I have a form

<?php echo form_tag('product/order') ?>
<?php echo radiobutton_tag('test[]', 'value1') ?> VALUE1
<?php echo radiobutton_tag('test[]', 'value2') ?> VALUE2
<?php echo input_tag('textfield') ?>
</form>

in the validation file for this action I wrote

fillin:
  enabled: on

When validation fails the form is repopulated (text input) but not the radio buttons.

I tracked down the problem to sfFillInForm.class.php:

        if ($type == 'checkbox' || $type == 'radio')
        {
          // checkbox and radio
          $element->removeAttribute('checked');
          if ($this->hasValue($values, $name) && ($this->getValue($values, $name) == $value || !$element->hasAttribute('value')))
          {
            $element->setAttribute('checked', 'checked');
          }
           
        }

There is a condition $this->getValue($values, $name) == $name. In case of the radio button $this->getValue() returns an array which is of course never equal to the value of the current radio button.

The getValue() method

  protected function getValue($values, $name)
  {
    if (array_key_exists($name, $values))
    {
      return $values[$name];
    }

    return sfToolkit::getArrayValueForPath($values, $name);
  }

will result in the execution of the second return statement, which returns an array.

I'm not sure about the overall purpose of sfToolkit::getArrayValueForPath(), so I currently don't know how to fix.

Change History

01/15/07 21:48:51 changed by fabien

  • status changed from new to closed.
  • resolution set to invalid.

Why name your radio button test[] as it can only have one value. If you rename your button to test, everything works fine.

Did I miss something?

01/15/07 22:27:49 changed by roga.moore

Oh, you are right. I think I missed something :)

I think it's because I just copied the snippet from the docs (http://www.symfony-project.com/book/trunk/templating_form_helpers) and changed it for my form.

<?php echo radiobutton_tag('status[]', 'value1', true) ?>
<?php echo radiobutton_tag('status[]', 'value2', false) ?>
// will generate in HTML
<input type="radio" name="status[]" id="status_value1" value="value1" checked="checked" />
<input type="radio" name="status[]" id="status_value2" value="value2" />

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.