All Solution List
Add New Solution
Pending Solution
Completed Solution
Checking Solution
All Cards Solution
Edit Solutions
Question
Need a validation dynamically for the any attribute ?
Assigner
Mukesh
Rashika
Atish
Aaditya
Kalyani
Brij
Developer
Mukesh
Rashika
Atish
Aaditya
Kalyani
Brij
Module
Product
Errors
Category
PHP
MYSQL
Status
Pending
Done
Checking
Working
Answer
step 5 : app/code/Enrich/Package/view/adminhtml/web/products/custom_validation.js in side js file add validation validator.addRule( 'validate-bonus-calc', function (value) { var packageType = $('select[name="product[package_type]"] option:selected').val(); var bonus_calc = $('select[name="product[bonus_calc]"] option:selected').val(); if (packageType==2 ) { return true; } if(packageType==3 && bonus_calc!=="") { return true; } else { return false; } }, $.mage.__('This is a required field.') ); " > step1- if attribute is required = true in upgradeData.php . then need required = false and change the version step2 - In mudule.xml file set the version as in upgradeData.php. step 3 - create app/code/Enrich/Incentive/Plugin/Product/Validationrules.php file wire the code getAttributeCode() == 'bonus_type'){ $rules['validate-bonus-type'] = true; } if ($attribute->getAttributeCode() == 'bonus_calc') { $rules['validate-bonus-calc'] = true; } if ($attribute->getAttributeCode() == 'bonus_value') { $rules['validate-bonus-value'] = true; } return $rules; } } step 4- config plugin in di.xml
step 5 : app/code/Enrich/Package/view/adminhtml/web/products/custom_validation.js in side js file add validation validator.addRule( 'validate-bonus-calc', function (value) { var packageType = $('select[name="product[package_type]"] option:selected').val(); var bonus_calc = $('select[name="product[bonus_calc]"] option:selected').val(); if (packageType==2 ) { return true; } if(packageType==3 && bonus_calc!=="") { return true; } else { return false; } }, $.mage.__('This is a required field.') );
SAVE