Dialog box Field Manditory

I Created a dialog box and added field customer_type1 it is a html field and also created a tax field it is a link field . when the user select Service then make the tax field is manditory. IS this possible .Below is my short code .

frappe.prompt([
{‘label’: ‘Customer Name’, ‘fieldname’: ‘customer_name’, ‘fieldtype’: ‘Data’, ‘reqd’: true},
{
‘label’: ‘Customer Type1’,
‘fieldname’: ‘customer_type1’,
‘fieldtype’: ‘HTML’,
‘options’: <div style="display: flex;"> <label style="margin-right: 20px !important;"> <input type="radio" name="customer_type1" value="Company" checked> Company </label> <label> <input type="radio" name="customer_type1" value="Individual"> Individual </label> <label> <input type="radio" name="customer_type1" value="Service"> Service </label> </div>
},

        {'label': 'Tax Category', 'fieldname': 'tax', 'fieldtype': 'Link','options':'Tax Category','mandatory_depends_on':''},
        
      {'label': 'Company', 'fieldname': 'company', 'fieldtype': 'Link', 'options': 'Company', 'default': frm.doc.company,'hidden': true},

])

Hii, please try below code

frappe.prompt([
			{'label': 'Customer Name', 'fieldname': 'customer_name', 'fieldtype': 'Data', 'reqd': true},
			{
				'label': 'Customer Type1',
				'fieldname': 'customer_type1',
				'fieldtype': 'HTML',
				'options': `
					<div style="display: flex;">
						<label style="margin-right: 20px !important;">
							<input type="radio" name="customer_type1" value="Company" checked onchange="updateTaxField()"> Company
						</label>
						<label>
							<input type="radio" name="customer_type1" value="Individual" onchange="updateTaxField()"> Individual
						</label>
						<label>
							<input type="radio" name="customer_type1" value="Service" onchange="updateTaxField()"> Service
						</label>
					</div>`
			},
			{'label': 'Tax Category', 'fieldname': 'tax', 'fieldtype': 'Link', 'options': 'Tax Category', 'mandatory_depends_on': ''},
			{'label': 'Company', 'fieldname': 'company', 'fieldtype': 'Link', 'options': 'Company', 'default': frm.doc.company, 'hidden': true},
		]);
		
		window.updateTaxField = function() {
			const selectedValue = document.querySelector('input[name="customer_type1"]:checked').value;
		
			if (selectedValue === "Service") {
				cur_dialog.set_df_property('tax', 'reqd', true)
			} else {
				cur_dialog.set_df_property('tax', 'reqd', false)
			}
		};
		
	},
3 Likes