Ricky Sharma
Ricky Sharma

Reputation: 1919

Not selecting store view in adminhtml Edit Section

Can anyone please help me. It might be really simple, seems like I am missing something.

I am trying to develop a very simple module here.

In the edit section, it's not selecting Region

enter image description here

store_id 1 is Australia

Code:

<?php

class Ubt_Faq_Block_Adminhtml_Faq_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{

protected function _prepareForm()
{
      $x = Mage::registry('ubt_faq')->getData();   
      var_dump($x);

      $form = new Varien_Data_Form();

      $fieldset = $form->addFieldset('faq_form', array(
             'legend'     => Mage::helper('ubt_faq')->__('FAQ'),
             'class'        => 'fieldset-wide',
      ));

      $fieldset->addField('faq_term', 'text', array(
             'name'      => 'faq_term',
             'label'     => Mage::helper('ubt_faq')->__('Term'),
             'class'     => 'required-entry',
             'required'  => true,
      ));

      $fieldset->addField('faq_answer', 'textarea', array(
             'name'      => 'faq_answer',
             'label'     => Mage::helper('ubt_faq')->__('Answer'),
             'class'     => 'required-entry',
             'required'  => true,
      ));           

      if (!Mage::app()->isSingleStoreMode()) {
           $fieldset->addField('store_ids', 'multiselect', array(
                 'label'     => Mage::helper('ubt_faq')->__('Visible In'),
                 'required'  => true,
                 'name'      => 'store_ids[]',
                 'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
                 'value'     => Mage::registry('ubt_faq')->getStoreId()
           ));          
       }

       if (Mage::registry('ubt_faq')) {
             $form->setValues(Mage::registry('ubt_faq')->getData());
       }
       $this->setForm($form);
       return parent::_prepareForm();
     }

}

In class Varien_Data_Form_Element_Multiselect extends Varien_Data_Form_Element_Abstract

$value = $this->getValue(); is coming null in getElementHtml();

I think this $value shouldn't be null as I am already assigning value to it.

Upvotes: 1

Views: 1265

Answers (3)

user1987049
user1987049

Reputation: 1

you need to add table store_id in the database of you module then add save action in module data controller.

Upvotes: 0

MagePal Extensions
MagePal Extensions

Reputation: 17656

Try updating form.php

  if (!Mage::app()->isSingleStoreMode()) {
       $fieldset->addField('store_ids', 'multiselect', array(
             'label'     => Mage::helper('ubt_faq')->__('Visible In'),
             'required'  => true,
             'name'      => 'store_ids',
             'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
       ));          
   }

Upvotes: 0

Vishal
Vishal

Reputation: 900

Hello check following steps may be help you

In Grid.php

 protected function _prepareCollection(){

      $collection Mage::getModel("faq/faq")->getCollection();

      foreach($collection as $link){

           if($link->getStoreId() && $link->getStoreId() != 0 ){

                $link->setStoreId(explode(',',$link->getStoreId()));

           }                
           else{                    
                $link->setStoreId(array('0'));                  
           }

       }

      $this->setCollection($collection);

      return parent::_prepareCollection();

 }

add column

 $this->addColumn("store_id", array(
      "header"        => Mage::helper("faq")->__("Store View"),         
      "index"        => "store_id",
      "type"          => "store",
      "store_all"     => true,
      "store_view"    => true,
      "sortable"      => true,
      "filter_condition_callback" => array($this,  
      "_filterStoreCondition"),
 ));

In form.php

 $fieldset->addField('store_id', 'multiselect', array(
      'name'      => 'store_id[]',
      'label'     => 'Store View',
      'title'     => '',
      'required'  => true,
      'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
 ));

Upvotes: 1

Related Questions