magentomagento-1.7magento-1.4magento-1.5magento-1.6

Conditions rules block - custom module


I create a custom extension and i need to add a “conditions rules tab” field in my custom form. the rule tab was displayed but cannot work.when i check in firebuger the following will give. ReferenceError: VarienRulesForm is not defined my code is

protected function _prepareForm()
{

    $model = Mage::getModel('callforprice/callforprice')->load();

    $form   = new Varien_Data_Form();
    $helper = Mage::helper('callforprice');

    $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
            ->setTemplate('promo/fieldset.phtml')
            ->setNewChildUrl($this->getUrl('callforprice/adminhtml_callforprice/newConditionHtml', array(
                'form'   => 'css_conditions_fieldset',
                'prefix' => 'css',
                'rule'   => base64_encode('callforprice/callforprice_product_rulecss'))));

    $fieldset = $form->addFieldset('css_conditions_fieldset', array(
                'legend' => $this->__('Conditions (leave blank for all products)')
            ))->setRenderer($renderer);

    $rule = Mage::getModel('callforprice/callforprice_product_rulecss');


    $rule->getConditions()->setJsFormObject('css_conditions_fieldset');
    $rule->getConditions()->setId('css_conditions_fieldset');

    $rule->setForm($fieldset);
    if ($model->getData('conditions_serialized') && is_array($model->getData('conditions_serialized')->getData('conditions'))) {
        $conditions = $model->getData('conditions_serialized')->getData('conditions');
        $rule->getConditions()->loadArray($conditions, 'css');
        $rule->getConditions()->setJsFormObject('css_conditions_fieldset');
    }

    $fieldset->addField('css_conditions', 'text', array(
        'name'     => 'css_conditions',
        'label'    => $this->__('Apply To'),
        'title'    => $this->__('Apply To'),
        'required' => true,
    ))->setRule($rule)->setRenderer(Mage::getBlockSingleton('rule/conditions'));

    $form->setValues($model->getData());
    $this->setForm($form);


    return parent::_prepareForm();
}

Solution

  • Try to load all js with css for rules.Try this

      <default>
            <reference name="head">
                <action method="addItem"><type>js</type><name>extjs/ext-tree.js</name><params/></action>
                <action method="addItem"><type>js</type><name>extjs/fix-defer.js</name><params/></action>
                <action method="addItem"><type>js</type><name>extjs/ext-tree-checkbox.js</name><params/></action>
                   <action method="addItem"><type>js</type><name>mage/adminhtml/rules.js</name><params/></action>
                <action method="addItem"><type>js_css</type><name>extjs/resources/css/ext-all.css</name><params/></action>
            </reference>
        </default>