1

i set the value for select field in admin form like this

$categories = Mage::getModel('test_yeezy/test')->getCollection();
        foreach ($categories as $category) {
          $values[] = array(
                        'value'     => $category->getCategoryId(),
                        'label'     => $category->getCategoryName()
                      );
        }

$fieldset->addField(
            'attribute_magento',
            'select',
            array(
                'name'   => 'attribute_magento0',
                'container_id' => 'attribute-magento0',
                'values' => $values,
        ));

the first value selected always the first record of the data, is there anyway to make the value selected first if it's not the first data, for example in html goes like this:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw" selected>VW</option>
  <option value="audi">Audi</option>
</select> 
1
  • Try adding 'value' => 'vw' after values => $values in your code. This should make VW default selection. Jan 5 '17 at 3:53
1

If I understand your question, try this way:

Adding 'value' => 'vw' after 'values' => $values in your addField

$fieldset->addField(
        'attribute_magento',
        'select',
        array(
            'name'   => 'attribute_magento0',
            'container_id' => 'attribute-magento0',
            'values' => $values,
            'value' => 'vw',
    ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.