Validating Mandatory Fields for Signature Controlled Items on Checkout Review Page

Overview

In SuiteCommerce, certain items classified as “Controlled : Signature Controlled” require additional prescriber information before an order can be placed. This article explains how to enforce frontend validation on the Checkout Review Page, especially when users add such items via a new tab, causing the cart to refresh dynamically.

Scenario

  • A user begins checkout without any Signature Controlled items.
  • In a separate tab, they add a Signature Controlled item to the cart.
  • Returning to the original checkout tab, the cart refreshes and now includes the controlled item.
  • The checkout review page must now validate that mandatory fields are filled before allowing order submission.

Mandatory Fields for Signature Controlled Items

If the cart contains any item with the class "Controlled : Signature Controlled", the following fields must be filled:

  • Prescriber Name
  • Prescriber Email (must be valid)
  • License Number

Frontend Validation Logic

Add the following logic to your checkout module (e.g., in a custom extension or override):

cart.on('beforeSubmit', function () {
	const cartModel = LiveOrderModel.getInstance();
	const lines = cartModel.get('lines')?.models || [];
	let hasSignatureItem = false;


	lines.forEach(function (line) {
		let itemClass = '';
		try {
			const item = line.get('item');
			itemClass = item?.attributes?.class?.trim() || '';
		} catch (e) {
			itemClass = '';
		}
		if (itemClass === 'Controlled : Signature Controlled') {
			hasSignatureItem = true;
		}
	});


	if (!hasSignatureItem) {
		return jQuery.Deferred().resolve(); // ✅ Proceed if no controlled item
	}


	// ✅ Safely get the custom fields from cartModel.attributes.options
	const options = cartModel.attributes.options || {};
	const prescriberName = options.custbody_prescriber_name?.trim() || '';
	const prescriberEmail = options.custbody_prescriber_email?.trim() || '';
	const licenseNumber = options.custbody_licensing_number?.trim() || '';


	const missingFields = [];
	if (!prescriberName) missingFields.push('Prescriber Name');
	if (!prescriberEmail) {
		missingFields.push('Prescriber Email');
	} else if (!/^[^s@]+@[^s@]+.[^s@]+$/.test(prescriberEmail)) {
		missingFields.push('Valid Email');
	}
	if (!licenseNumber) missingFields.push('License Number');


	if (missingFields.length > 0) {
		const global_view_message = new GlobalViewsMessageView({
			message: 'The following fields are required before placing the order:n' + missingFields.join(', '),
			type: 'error',
			closable: true
		});
		const headerContainer = document.querySelector('.order-wizard-step-header');
		if (headerContainer) {
			headerContainer.appendChild(global_view_message.render().$el[0]);
		}
		return jQuery.Deferred().reject(); // ❌ Stop order
	}


	return jQuery.Deferred().resolve(); // ✅ Allow order
});

Leave a comment

Your email address will not be published. Required fields are marked *