Pregunta

I am having a form, and a select type field which is rendering good and have correct options but when I am editing an existing record it won't point to the corresponding value.

CODE

$fieldset->addField(
                'segment',
                'select',
                [
                    'name' => 'segment',
                    'label' => __('Segment'),
                    'id' => 'segment',
                    'title' => __('Segment'),
                    'required' => true,
                    'value' => $model->getSegmentCode(),
                    'values' => $options
                ],
                'sender_email'
            );

What I always got is select with options.

I can't screenshot when its open :D.

enter image description here

¿Fue útil?

Solución

I believe the block loads values based on the data keys. Based on your sample code I am guessing the value you want is in the column segment_code because $model->getSegmentCode() is probably the same as $model->getData('segment_code') if you are extending AbstractModel or DataObject.

If that's the case then try changing the field name to segment_code and it should fill the value accordingly.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top