I have exactly same question asked over here: https://stackoverflow.com/questions/25291470/can-we-make-widget-options-validaton-in-magento

I want to know is there any easy way I can validate my widget options input or I should write all validation codes by myself ?

Something like, check if the option is not a negative number or similar things.

Any help will be appreciated. Thanks for your help.

  • The only way i know to do this is by either doing the validation in the template using the js validator, or defining a custom block and writing validating in the block. Either way the validation tags do not exist and looking at Magento 2, it doesn't look like they will be adding them any time soon. – Shaughn Apr 29 '15 at 22:24
  • @Shaughn How can I do the validation for widget options ? Can you provide some examples ? – chamich Apr 30 '15 at 11:37
  • I have same problem. – Michel Gokan Khan May 2 '15 at 10:17
  • anyone can help ? – chamich May 8 '15 at 15:30
  • anybody ??????? – chamich May 15 '15 at 17:29

Take a look at how Magento defined a helper block in the Mage_Catalog module. In their widget.xml they define the helper block:

<helper_block> <type>adminhtml/catalog_product_widget_chooser</type> ... </helper_block>

This leads us to class Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser where you can see they define some JS to do special things on the widget edit form. You should be able to add your own validation in a similar way that's custom to only this widget type.

  • So, there is no way currently right ? I have to implement it myself? – chamich Jun 8 '15 at 21:38
  • 1
    Right - the easiest way to do this will be to look at how Magento implemented it for the Chooser block. You should be able to reuse most of the concepts in the above mentioned class. – David Robinson Jun 9 '15 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.