Can we make Widget Options validaton in magento?

If we add end-of-file configurations to the system.xml file, we can add validation for each field using the validate tag, as shown below:

<duration> <label> ...</label> <frontend_type >text</frontend_type> <validate>required-entry validate-number</validate> <source_model>adminhtml/system_config_source_yesno</source_model> <sort_order>70</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </duration> 

My question is a similar way to do the same with widget options in magento? For example, in the widget.xml file:

 <widget type="common/widget"> <name>new widget</name> <description>new widget</description> <parameters> <template> <visible>0</visible> <value>template.phtml</value> </template> <after translate="label"> <visible>1</visible> <label>...</label> <type>text</type> <validate>required-entry validate-number</validate> </after> </parameters> </widget> 
+5
source share
2 answers

You cannot do this directly through XML. However, you can create a custom block, set the css validation class there and use it as a type in widget.xml.

Application / code / local / Mynamespace / MyModule / etc. /widget.xml:

 <somefield> <required>1</required> <visible>1</visible> <label>Some number</label> <type>mynamespace_mymodule/element_numeric</type> </somefield> 

Application / code / local / Mynamespace / MyModule / block / element / Numeric.php:

 class Mynamespace_Mymodule_Block_Element_Numeric extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element { public function render(Varien_Data_Form_Element_Abstract $element) { $element->setType('text'); $element->addClass('validate-digits'); parent::render($element); } } 

It is important that the custom element block extend the Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element class so that it displays correctly in the field set.

+1
source

@ Joe Mizzi's method rendering should return a value

 class Mynamespace_Mymodule_Block_Element_Numeric extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element { public function render(Varien_Data_Form_Element_Abstract $element) { $element->setType('text'); $element->addClass('validate-digits'); return parent::render($element); } } 
+1
source

Source: https://habr.com/ru/post/1200245/


All Articles