Magento 1.9.3 add custom validations for Product form in admin panel












0















I have added 2 custom attribute on product form.
1.Package type 2.Quantity



MY package type can be single /multiple.
When it is multiple , I want to show Quantity inputbox & also , want to apply required validations to it..
For Single ,it should be hidden.



How can I ado this ?
& where can I add validations ?



I am new to magento ,so can anyone help me with this?










share|improve this question














bumped to the homepage by Community 7 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I have added 2 custom attribute on product form.
    1.Package type 2.Quantity



    MY package type can be single /multiple.
    When it is multiple , I want to show Quantity inputbox & also , want to apply required validations to it..
    For Single ,it should be hidden.



    How can I ado this ?
    & where can I add validations ?



    I am new to magento ,so can anyone help me with this?










    share|improve this question














    bumped to the homepage by Community 7 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I have added 2 custom attribute on product form.
      1.Package type 2.Quantity



      MY package type can be single /multiple.
      When it is multiple , I want to show Quantity inputbox & also , want to apply required validations to it..
      For Single ,it should be hidden.



      How can I ado this ?
      & where can I add validations ?



      I am new to magento ,so can anyone help me with this?










      share|improve this question














      I have added 2 custom attribute on product form.
      1.Package type 2.Quantity



      MY package type can be single /multiple.
      When it is multiple , I want to show Quantity inputbox & also , want to apply required validations to it..
      For Single ,it should be hidden.



      How can I ado this ?
      & where can I add validations ?



      I am new to magento ,so can anyone help me with this?







      magento-1.9 custom-options validation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 5 '16 at 10:28









      user7193478user7193478

      516




      516





      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I am not sure but you can normally create 4 attributes from admin panel. And through JS you can hide those 2 attributes and make them required when it is necessary.



          If this works, then this scenario is possible otherwise it is not possible to make them required field on multiple selection. Because then the scenario will be: You want to add that attribute only when multiple selection happens and its not possible to add attribute only at that time.






          share|improve this answer
























          • how can I do this through js ? where can I add js code?

            – user7193478
            Dec 6 '16 at 4:29











          • You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

            – Gaurav Agrawal
            Dec 6 '16 at 8:41



















          0














          I solved this by adding this in config.xml file :



          <adminhtml>
          <layout>
          <updates>
          <adminhtml_catalog_product_edit>
          <file>custom_local.xml</file>
          </adminhtml_catalog_product_edit>
          </updates>
          </layout>
          </adminhtml>


          & placed custom_local.xml under appdesignadminhtmldefaultdefaultlayout folder .



          In custom_local.xml, I added my custom js file for both add & edit product as :



           <layout>
          <adminhtml_catalog_product_new>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script></action>
          </reference>
          </adminhtml_catalog_product_new>

          <adminhtml_catalog_product_edit>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script> </action>
          </reference>
          </adminhtml_catalog_product_edit>
          </layout>


          I placed my admin-custom.js under js folder in root directory & added following validations :



          if(Validation) 
          {
          Validation.add('conditional-required', 'This is a required field.', function(v) {
          var pack_type = $('pack_type').getValue();
          if(pack_type != 0)
          {
          return ( (v != null) && (v.length != 0));
          }
          else
          {
          return true;
          }

          });
          }
          document.observe("dom:loaded", bodyOnload);
          function bodyOnload() {

          $('bottle_litres').addClassName('required-entry');
          //alert($('pack_type').getValue());
          var pack_type = $('pack_type').getValue();
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }


          $('pack_type').observe('change', function(e) {
          pack_type = $('pack_type').getValue();//alert(pack_type);
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }
          });

          }


          & it worked :-)






          share|improve this answer


























          • I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

            – senthil
            Oct 11 '17 at 12:11













          • Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

            – zus
            Sep 28 '18 at 10:08











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f148846%2fmagento-1-9-3-add-custom-validations-for-product-form-in-admin-panel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I am not sure but you can normally create 4 attributes from admin panel. And through JS you can hide those 2 attributes and make them required when it is necessary.



          If this works, then this scenario is possible otherwise it is not possible to make them required field on multiple selection. Because then the scenario will be: You want to add that attribute only when multiple selection happens and its not possible to add attribute only at that time.






          share|improve this answer
























          • how can I do this through js ? where can I add js code?

            – user7193478
            Dec 6 '16 at 4:29











          • You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

            – Gaurav Agrawal
            Dec 6 '16 at 8:41
















          0














          I am not sure but you can normally create 4 attributes from admin panel. And through JS you can hide those 2 attributes and make them required when it is necessary.



          If this works, then this scenario is possible otherwise it is not possible to make them required field on multiple selection. Because then the scenario will be: You want to add that attribute only when multiple selection happens and its not possible to add attribute only at that time.






          share|improve this answer
























          • how can I do this through js ? where can I add js code?

            – user7193478
            Dec 6 '16 at 4:29











          • You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

            – Gaurav Agrawal
            Dec 6 '16 at 8:41














          0












          0








          0







          I am not sure but you can normally create 4 attributes from admin panel. And through JS you can hide those 2 attributes and make them required when it is necessary.



          If this works, then this scenario is possible otherwise it is not possible to make them required field on multiple selection. Because then the scenario will be: You want to add that attribute only when multiple selection happens and its not possible to add attribute only at that time.






          share|improve this answer













          I am not sure but you can normally create 4 attributes from admin panel. And through JS you can hide those 2 attributes and make them required when it is necessary.



          If this works, then this scenario is possible otherwise it is not possible to make them required field on multiple selection. Because then the scenario will be: You want to add that attribute only when multiple selection happens and its not possible to add attribute only at that time.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 5 '16 at 12:41









          Gaurav AgrawalGaurav Agrawal

          4241520




          4241520













          • how can I do this through js ? where can I add js code?

            – user7193478
            Dec 6 '16 at 4:29











          • You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

            – Gaurav Agrawal
            Dec 6 '16 at 8:41



















          • how can I do this through js ? where can I add js code?

            – user7193478
            Dec 6 '16 at 4:29











          • You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

            – Gaurav Agrawal
            Dec 6 '16 at 8:41

















          how can I do this through js ? where can I add js code?

          – user7193478
          Dec 6 '16 at 4:29





          how can I do this through js ? where can I add js code?

          – user7193478
          Dec 6 '16 at 4:29













          You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

          – Gaurav Agrawal
          Dec 6 '16 at 8:41





          You can include your JS in validation.js, because it is available through the admin section. And you have to check the attribute field id, it is named by attribute name. Now you can simply hide those attributes. And you can check the multiselect by Onselect method in JS.

          – Gaurav Agrawal
          Dec 6 '16 at 8:41













          0














          I solved this by adding this in config.xml file :



          <adminhtml>
          <layout>
          <updates>
          <adminhtml_catalog_product_edit>
          <file>custom_local.xml</file>
          </adminhtml_catalog_product_edit>
          </updates>
          </layout>
          </adminhtml>


          & placed custom_local.xml under appdesignadminhtmldefaultdefaultlayout folder .



          In custom_local.xml, I added my custom js file for both add & edit product as :



           <layout>
          <adminhtml_catalog_product_new>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script></action>
          </reference>
          </adminhtml_catalog_product_new>

          <adminhtml_catalog_product_edit>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script> </action>
          </reference>
          </adminhtml_catalog_product_edit>
          </layout>


          I placed my admin-custom.js under js folder in root directory & added following validations :



          if(Validation) 
          {
          Validation.add('conditional-required', 'This is a required field.', function(v) {
          var pack_type = $('pack_type').getValue();
          if(pack_type != 0)
          {
          return ( (v != null) && (v.length != 0));
          }
          else
          {
          return true;
          }

          });
          }
          document.observe("dom:loaded", bodyOnload);
          function bodyOnload() {

          $('bottle_litres').addClassName('required-entry');
          //alert($('pack_type').getValue());
          var pack_type = $('pack_type').getValue();
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }


          $('pack_type').observe('change', function(e) {
          pack_type = $('pack_type').getValue();//alert(pack_type);
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }
          });

          }


          & it worked :-)






          share|improve this answer


























          • I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

            – senthil
            Oct 11 '17 at 12:11













          • Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

            – zus
            Sep 28 '18 at 10:08
















          0














          I solved this by adding this in config.xml file :



          <adminhtml>
          <layout>
          <updates>
          <adminhtml_catalog_product_edit>
          <file>custom_local.xml</file>
          </adminhtml_catalog_product_edit>
          </updates>
          </layout>
          </adminhtml>


          & placed custom_local.xml under appdesignadminhtmldefaultdefaultlayout folder .



          In custom_local.xml, I added my custom js file for both add & edit product as :



           <layout>
          <adminhtml_catalog_product_new>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script></action>
          </reference>
          </adminhtml_catalog_product_new>

          <adminhtml_catalog_product_edit>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script> </action>
          </reference>
          </adminhtml_catalog_product_edit>
          </layout>


          I placed my admin-custom.js under js folder in root directory & added following validations :



          if(Validation) 
          {
          Validation.add('conditional-required', 'This is a required field.', function(v) {
          var pack_type = $('pack_type').getValue();
          if(pack_type != 0)
          {
          return ( (v != null) && (v.length != 0));
          }
          else
          {
          return true;
          }

          });
          }
          document.observe("dom:loaded", bodyOnload);
          function bodyOnload() {

          $('bottle_litres').addClassName('required-entry');
          //alert($('pack_type').getValue());
          var pack_type = $('pack_type').getValue();
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }


          $('pack_type').observe('change', function(e) {
          pack_type = $('pack_type').getValue();//alert(pack_type);
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }
          });

          }


          & it worked :-)






          share|improve this answer


























          • I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

            – senthil
            Oct 11 '17 at 12:11













          • Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

            – zus
            Sep 28 '18 at 10:08














          0












          0








          0







          I solved this by adding this in config.xml file :



          <adminhtml>
          <layout>
          <updates>
          <adminhtml_catalog_product_edit>
          <file>custom_local.xml</file>
          </adminhtml_catalog_product_edit>
          </updates>
          </layout>
          </adminhtml>


          & placed custom_local.xml under appdesignadminhtmldefaultdefaultlayout folder .



          In custom_local.xml, I added my custom js file for both add & edit product as :



           <layout>
          <adminhtml_catalog_product_new>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script></action>
          </reference>
          </adminhtml_catalog_product_new>

          <adminhtml_catalog_product_edit>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script> </action>
          </reference>
          </adminhtml_catalog_product_edit>
          </layout>


          I placed my admin-custom.js under js folder in root directory & added following validations :



          if(Validation) 
          {
          Validation.add('conditional-required', 'This is a required field.', function(v) {
          var pack_type = $('pack_type').getValue();
          if(pack_type != 0)
          {
          return ( (v != null) && (v.length != 0));
          }
          else
          {
          return true;
          }

          });
          }
          document.observe("dom:loaded", bodyOnload);
          function bodyOnload() {

          $('bottle_litres').addClassName('required-entry');
          //alert($('pack_type').getValue());
          var pack_type = $('pack_type').getValue();
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }


          $('pack_type').observe('change', function(e) {
          pack_type = $('pack_type').getValue();//alert(pack_type);
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }
          });

          }


          & it worked :-)






          share|improve this answer















          I solved this by adding this in config.xml file :



          <adminhtml>
          <layout>
          <updates>
          <adminhtml_catalog_product_edit>
          <file>custom_local.xml</file>
          </adminhtml_catalog_product_edit>
          </updates>
          </layout>
          </adminhtml>


          & placed custom_local.xml under appdesignadminhtmldefaultdefaultlayout folder .



          In custom_local.xml, I added my custom js file for both add & edit product as :



           <layout>
          <adminhtml_catalog_product_new>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script></action>
          </reference>
          </adminhtml_catalog_product_new>

          <adminhtml_catalog_product_edit>
          <reference name="head">
          <action method="addJs"><script>admin-custom.js</script> </action>
          </reference>
          </adminhtml_catalog_product_edit>
          </layout>


          I placed my admin-custom.js under js folder in root directory & added following validations :



          if(Validation) 
          {
          Validation.add('conditional-required', 'This is a required field.', function(v) {
          var pack_type = $('pack_type').getValue();
          if(pack_type != 0)
          {
          return ( (v != null) && (v.length != 0));
          }
          else
          {
          return true;
          }

          });
          }
          document.observe("dom:loaded", bodyOnload);
          function bodyOnload() {

          $('bottle_litres').addClassName('required-entry');
          //alert($('pack_type').getValue());
          var pack_type = $('pack_type').getValue();
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }


          $('pack_type').observe('change', function(e) {
          pack_type = $('pack_type').getValue();//alert(pack_type);
          if(pack_type == 0) {
          $('no_of_bottles').closest('tr').hide();
          $('no_of_bottles').removeClassName('conditional-required');
          } else {
          $('no_of_bottles').closest('tr').show();
          $('no_of_bottles').addClassName('conditional-required');
          }
          });

          }


          & it worked :-)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 7 '16 at 6:34









          Gopal Patel

          2,9912930




          2,9912930










          answered Dec 7 '16 at 5:25









          user7193478user7193478

          516




          516













          • I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

            – senthil
            Oct 11 '17 at 12:11













          • Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

            – zus
            Sep 28 '18 at 10:08



















          • I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

            – senthil
            Oct 11 '17 at 12:11













          • Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

            – zus
            Sep 28 '18 at 10:08

















          I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

          – senthil
          Oct 11 '17 at 12:11







          I followed the mentioned way so that the class(conditional-required) adding to the field, but the message is not showing. how can i add the custom validation method in admin end.

          – senthil
          Oct 11 '17 at 12:11















          Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

          – zus
          Sep 28 '18 at 10:08





          Anyone guide me how can i integrate Custom Feedback Form Code Into Magento - magento.stackexchange.com/q/244255/57334

          – zus
          Sep 28 '18 at 10:08


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f148846%2fmagento-1-9-3-add-custom-validations-for-product-form-in-admin-panel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy