Varien_Data_Form Fieldset Options

Updated . Posted . Visible to the public.

Wide field

Useful for long text.

$form = new Varien_Data_Form();

$fieldset = $form->addFieldset('base_fieldset', [
    'legend' => Mage::helper('im')->__('Comment'),
   // 'comment' => 'non-html text is rendered before other fields',
    'class' => 'fieldset-wide'
]);

        $fieldset->addField('comment', 'textarea', [
            'name'      => 'comment',  
            'required'  => true,
            'after_element_html' => "<script>$('comment').up('td').previous('td').remove();$('comment').up('td').colspan=2;</script>"
        ]);

Image

Render a Block in Fieldset

Ref app\design\adminhtml\default\default\template\widget\form\renderer\fieldset.phtml

$block = $this->getLayout()->createBlock('benefit/adminhtml_utilization_edit_form_inputs');
$form->addFieldset('utilization_form', [
    'legend' => $helper->__('Benefit Utilization'),
    'no_container' => true,
    'html_content' => $block->toHtml()
]);

Image

Box Left and Box Right Hack

$fieldset = $form->addFieldset('plan_info', [
    'legend' => $helper->__('Plan Information'),
    'header_bar' => '<a target="_blank" :href="\''
        . $this->getUrl('*/plan/edit')
        . 'id/\' + plan.info.plan_id">Edit</a>',
    'fieldset_container_id' => '" class="box-left'
]);

$fieldset->addField('company', 'label', [
    'label'     => $helper->__('Company'),
    'bold'      => true,
    'value'     => '{{ plan.info.company }}'
]);

$fieldset = $form->addFieldset('plan_conditions', [
    'legend' => $helper->__('Plan Conditions'),
    'fieldset_container_id' => 'plan-conditions" class="box-right'
]);

$fieldset->addField('is_active', 'label', [
    'label'     => $helper->__('Is Active'),
    'bold'      => true,
    'value'     => '{{ plan.info.is_active }}'
]);

Image

Clear Preceding Float in 'fieldset_container_id'

        $body = print_r($model->getRequestBody(), true);
        $fieldset = $form->addFieldset('request_body1', [
            'legend' => $helper->__('Request Body'),
            'fieldset_container_id' => 'request-body1-container" style="clear: both;" class="box-left',
            'html_content' => "<pre><code class=\"language-ini\">$body</code></pre>"
        ]);

Add a Button to Fieldset

        /** @var Mage_Adminhtml_Block_Widget_Button $block */
        $block = $this->getLayout()->createBlock('adminhtml/widget_button');
        $block->setData([
            'label' => $helper->__('Recalculate Used Dose Qty'),
            'onclick' => 'window.location.href=\''.$this->getUrl('*/*/usedDose').'\'',
            'class' => 'save'
        ]);
        $fieldset = $form->addFieldset('dose_info', [
            'legend' => $helper->__('Dose Qty'),
            'header_bar' => $block->toHtml()
        ]);

Image

Add at the beginning of the form

        // Add Clinic Undertaking Information as the first fieldset.
        $fieldset = $form->addFieldset(
            'clinic_undertaking_info',
            [
                'legend' => $helper->__('Clinic Undertaking Information'),
                'fieldset_container_id' => '" class="box-left'
            ],
            '^'
        );
kiatng
Last edit
kiatng
Posted by kiatng to OpenMage (2020-06-14 04:06)