Mandatory Fields based on category

I have products categories like Phone and accessories. I want to set one Check field as Mandatory IF the item fall under Phone and sub category… Otherwise it should not be mandatory…

You can use form methods,
frm.set_df_property('fieldname', 'reqd', 1)