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 \app\design\adminhtml\default\default\layout\
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 :-)