Need to set field to mandatory when a check box is selected

Hi All
I am evaluating erpnext. have some knowledge of java script. on the suppliers form i have added 1 new field that is necessary when a supplier is local. i have also added a check box called foreign. when the check box is selected, it should set the new field should not be mandatory.

please see code below:

frappe.ui.form.on(‘Supplier’, {
refresh: function(frm) {
if(frm.doc.foreign == 1) {
frm.set_df_property(“newfield”, “reqd”, 0);
frm.set_df_property(“newfield”, “reqd”, 1);


any help will be welcomed.