Deselect options in dropdown

Currently, if you choose the option in the dropdown, you can change it, but it’s impossible to completely deselect it (leave it empty).

I’d like this feature to be released in the future :slightly_smiling_face:

1 Like

While this option isn’t available right away, you can achieve this result using this code in the Custom JS section on the Settings tab of your widget’s settings:

const WIDGET_ID = 'Your Widget ID';

const waitForElement = (selector, root = document) =>
	new Promise((res) => {
		let i = 0;

		const check = () => {
			const component = root.querySelector(selector);

			if (component) {
				res(component);
			} else if (i !== 50) {
				setTimeout(check, 100);
				i++;
			}
		};

		check();
	});

waitForElement(`.elfsight-app-${WIDGET_ID} > div`).then(
	(container) => {
		container.addEventListener('click', () => {
			const options = container.querySelectorAll('option');

			if (options.length) {
				Array.from(options).forEach((option) => {
					option.removeAttribute('disabled');
				});
			}
		});
	}
);

In the 1st line of the code, you should replace Your Widget ID with the ID of your widget :slightly_smiling_face:

1 Like