Related
Following is my Form Field Code.
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);
How to Make a Status Field Bydefault Enable in Magento Form?
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'value' => '1',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);
I have a grid, in this grid I have filter. Grid code is:
$this->widget('booster.widgets.TbGridView', array(
'id' => 'sam',
'type' => 'striped bordered condensed',
'dataProvider' => $dataProvider,
'responsiveTable' => true,
'enableHistory' => true,
'filter' => $asset,
'columns' => array(
array(
'name' => 'id',
'header' => '#',
'filter' => false,
'type' => 'text',
),
array(
'name' => 'user',
'header' => 'Registered By',
'type' => 'text',
'value' => '$data["assignedBy"]',
),
array(
'name' => 'createdAt',
'header' => 'Created At',
'type' => 'datetime',
),
array(
'name' => 'serial',
'header' => 'Serial',
),
array(
'name' => 'brand',
'header' => 'Brand',
),
array(
'name' => 'model',
'header' => 'Model',
),
array(
'name' => 'assetType',
'type' => 'text',
'filter' => \wsi\it\model\AssetType::getRepository()->getTypeTree(),
'value' => '$data["assetTypeName"]',
'header' => 'Type',
),
array(
'name' => 'assigned',
'value' => '(isset($data["assignedTo"]))? $data["assignedTo"]:null',
'header' => 'Assigned To',
),
array(
'name' => 'location',
'filter' => \wsi\hr\Facade::getInstance()->getLocations(),
'value' => '$data["locationName"]',
'header' => 'Location',
),
array(
'name' => 'status',
'header' => 'Status',
'filter' => \wsi\it\model\Asset::$statusOptionList,
'value' => '\wsi\it\model\Asset::$statusOptionList[$data["status"]]',
),
array(
'class' => 'booster.widgets.TbButtonColumn',
'template' => '{view} {update} {delete}',
'header' => '',
'buttons' => array(
'update' => array(
'url' => '\Yii::app()->controller->createUrl("asset/create", array("id"=>$data["id"]))',
),
'view' => array(
'url' => '\Yii::app()->controller->createUrl("asset/view", array("id"=>$data["id"]))',
),
'delete' => array(
'url' => '\Yii::app()->controller->createUrl("asset/delete", array("id"=>$data["id"]))',
),
),
),
)
)
);
When Grid is rendered in the browser you can see that the filter list box contains html which is not parsed fully!
I had this problem with Yii-Booster before and I solved it with an option which I passed to that widget ('htmlOptions' => 'encode' => false) and It prevents to be treated as string, so browsers would parse it as space. That code which You can see below does not work for grid filter!
$form->dropDownListGroup($formModel, 'segmentList', array(
'wrapperHtmlOptions' => array(
'class' => 'col-md-6'
),
'widgetOptions' => array(
'data' => $segmentTreeArray,
'htmlOptions' => array(
>>> 'encode' => false, <<<
)
),
'hint' => "Press CTRL to add another item, otherwise others will be deselected",
));
BUT I am sure that I have to pass same "encode" => false to filter list too, I just can not find under what key I should pass it (htmlOptions did not work).
I have a field in the form like this:
$this -> add(array(
'type' => 'field-set',
'name' => 'meta_properties',
'options' => array(
'label' => "Meta Properties",
),
'elements' => array(
)
));
$meta_fieldSet = $this -> get('meta_properties');
$meta_fieldSet->add(array(
'name' => 'meta_title',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Title',
),
));
$meta_fieldSet->add(array(
'name' => 'meta_description',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Description',
),
));
$meta_fieldSet->add(array(
'name' => 'meta_keywords',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Keywords',
)
));
And in my input filter class I have
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_title',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_description',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_keywords',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
It is not validating. How to validate InputFilter?
When creating Fieldsets you need to extend \Zend\Form\Fieldset. Try creating a fieldset like this:
<?php
/**
* Fieldset Example
*/
namespace Module\Form;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class NewFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
// we want to ignore the name passed and give it our own
parent::__construct('appointment');
// Use the model you are associating with your fieldset here
$this->setHydrator(new ClassMethodsHydrator(false))
->setObject(new MyModel)
->setLabel('My Model');
$this->add(array(
'name' => 'fieldset_item_1',
'type' => 'Select',
'options' => array(
'label' => 'FieldSet Item 1',
)
));
$this->add(array(
'name' => 'fieldset_item_2',
'type' => 'Select',
'options' => array(
'label' => 'FieldSet Item 2',
)
));
}
/**
* Sets up the input filter specification and returns it
*/
public function getInputFilterSpecification()
{
return array(
'fieldset_item_1' => array(
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
),
'fieldset_item_2' => array(
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
),
);
}
}
Then you can use it in your form like this:
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'fieldset',
'options' => array(
'label' => '',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'use_as_base_fieldset' => false,
'create_new_objects' => true,
'target_element' => array('type' => 'Module\Form\NewFieldset')
),
));
Now when you perform $form->isValid() in a controller it will validate the fieldset. In addition, you can now make some fancy front-end code to dynamically add and remove fieldsets from the form and they will all get validated.
I want to show Display Action labes in single row instead of combobox in grid on admin side magento .My code for combobox is
$this->addColumn('action',
array(
'header' => Mage::helper('mymodule')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('mymodule')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('Delete'),
'url' => array('base'=> '*/*/delete'),
'confirm' => Mage::helper('mymodule')->__('Are you sure?'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('View'),
'url' => array('base'=> '*/*/view'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
See image for combobox style.
Checkout this code
$this->addColumn('actions', array(
'header' => Mage::helper('adminnotification')->__('Actions'),
'width' => '250px',
'sortable' => false,
'renderer' => 'adminhtml/notification_grid_renderer_actions',
));
under class Mage_Adminhtml_Block_Notification_Grid
and also see the class Mage_Adminhtml_Block_Notification_Grid_Renderer_Actions
If you have still any problem let me know.
I wrote a module to have my own menu bar, rather than just using categories as a menu bar.
So, here I want to show already added menus while adding new menu in the Tab/Form.php in my custom menu module. How can I show all of the existing menu names as a dropdown/options list on the form. Here is the code that I used to have menu form.
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
In this I want to show all the added menus under the parent menu option. What should I write in my Model class so that I can have a drop down list to show them all, and after adding it should be added to database.
Please help me, am struggling here.
You can do this by adding these lines.
It will show already added menus as a dropdown list so that you can choose any of them as a parent menu for current item.
$_menus = Mage::getSingleton('menus/menus')->getCollection();
foreach($_menus as $item)
{
if($item->getParent == NULL){
$_menuItems[] = array(
'value' => $item->getId(),
'label' => $item->getTitle(),
);
}
}
$note = "Choose the parent menus for this item";
$fieldset->addField('parent', 'select', array(
'name' => 'parent',
'label' => Mage::helper('menus')->__('Parent Menu'),
'title' => Mage::helper('menus')->__('Parent Menu'),
'required' => false,
'note' => $note,
'class' => 'HideIt',
'values' => $_menuItems,
));