<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Styling select input dropdown in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358939#M17824</link>
    <description>&lt;P&gt;Hi Anton,&lt;BR /&gt;&lt;BR /&gt;I probably should've specific that I'm using hubspot form with &lt;STRONG&gt;Set as raw HTML form&lt;/STRONG&gt; option checked, with shortcode generated by HubSpot plugin for WordPress. I don't need to create a custom dropdown, but rather to modify the one hubspot provides which I managed to do, but the validation doesn't seem to like my solution. Here's the JavaScript code I have written for this problem so you get the idea of what I'm trying to accomplish:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;const styleSelectInputs = _ =&amp;gt; {
	let openedDropdown;

	const openDropdown = e =&amp;gt; {
		const input = e.target;
		const dropdown = input.nextElementSibling;
		dropdown.style.display = 'block';
		openedDropdown = dropdown;
	}

	const closeDropdown = _ =&amp;gt; {
		openedDropdown.style.display = 'none';
	}

	const setSelectValue = e =&amp;gt; {
		e.stopPropagation();
		const selected = e.target;
		const allOptions = [...selected.parentNode.querySelectorAll('.hs-custom-option')]
		
		selected.classList.add('active');
		allOptions.forEach(option =&amp;gt; option !== selected &amp;amp;&amp;amp; option.classList.remove('active'));

		const input = selected.parentNode.previousElementSibling;
		const options = [...input.options];
		let selected_opt, selected_idx;
		options.forEach((option, i) =&amp;gt; {
			if (option.value === selected.dataset.value) {
				selected_opt = option;
				selected_idx = i;
			}
		});

		selected_opt.selected = true;
		input.value = selected_opt.value;
		input.selectedIndex = selected_idx;
		input.classList.remove('invalid');
		input.classList.remove('error');
		
		closeDropdown();
	}

	const createOption = option =&amp;gt; {
		const opt = document.createElement('div');
		opt.setAttribute('class', 'hs-custom-option');
		opt.dataset.value = option.value;
		opt.innerHTML = option.innerHTML;
		opt.addEventListener('click', setSelectValue);

		return opt;
	}

	const stylize = input =&amp;gt; {
		const options = [...input.options];
		const newOptions = options.map(option =&amp;gt; createOption(option));

		const container = document.createElement('div');
		container.setAttribute('class', 'hs-custom-container');
		container.style.display = 'none';
		newOptions.forEach(option =&amp;gt; container.appendChild(option));

		input.insertAdjacentElement('afterend', container);
	}

	const init = _ =&amp;gt; {
		const select_inputs = [...document.querySelectorAll('.hs-form fieldset .hs-form-field .input select.hs-input')]
		select_inputs.forEach(input =&amp;gt; {
			stylize(input);
			input.addEventListener('click', openDropdown);
		})

		document.addEventListener('click', e =&amp;gt; {
			if (e.target.nodeName !== 'SELECT' &amp;amp;&amp;amp; !e.target.classList.contains('hs-input')) {
				closeDropdown();
			}
		})
	}

	init();
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jul 2020 21:17:17 GMT</pubDate>
    <dc:creator>unesic</dc:creator>
    <dc:date>2020-07-31T21:17:17Z</dc:date>
    <item>
      <title>Styling select input dropdown</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358901#M17822</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I'm trying to style the &lt;STRONG&gt;select input field's dropdown&lt;/STRONG&gt; on a website so it follows the styleguide. I've managed to style the select field itself, but styling the dropdown turned out to be really tricky.&lt;BR /&gt;&lt;BR /&gt;I added custom JavaScript that creates and injects custom HTML element that acts like a dropdown populated with custom elements that are options. It seems like everything works as expected until the form validation kicks in.&lt;BR /&gt;&lt;BR /&gt;I made sure the real option's &lt;STRONG&gt;selected&lt;/STRONG&gt; property is set to &lt;STRONG&gt;true&lt;/STRONG&gt;, and its parent &lt;STRONG&gt;select&lt;/STRONG&gt; field properties &lt;STRONG&gt;value&lt;/STRONG&gt; and &lt;STRONG&gt;selectedIndex&lt;/STRONG&gt; are also &lt;STRONG&gt;set accordingly&lt;/STRONG&gt;. Inspecting the code in the developer console shows that both the &lt;STRONG&gt;value&lt;/STRONG&gt; and &lt;STRONG&gt;selectedIndex&lt;/STRONG&gt; are set, option's &lt;STRONG&gt;selected&lt;/STRONG&gt; property is also &lt;STRONG&gt;set to true&lt;/STRONG&gt;, but the form still throws an error.&lt;BR /&gt;&lt;BR /&gt;Am I missing something obvious here?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 19:08:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358901#M17822</guid>
      <dc:creator>unesic</dc:creator>
      <dc:date>2020-07-31T19:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Styling select input dropdown</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358929#M17823</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/140543"&gt;@unesic&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;since the regular/default dropdown is always rendered by the browser/os it's quite hard/impossible to style this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this doesn't mean that it's impossible at all. There are a few options how to generate/style a dropdown without using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;select&amp;gt;
&amp;lt;option&amp;gt;Lorem ipsum &amp;lt;/option&amp;gt;
&amp;lt;option&amp;gt;Ipsum dolor&amp;lt;/option&amp;gt;&lt;BR /&gt;...
&amp;lt;/select&amp;gt;&lt;/PRE&gt;
&lt;P&gt;One possible solution might be to create a regular list like&lt;/P&gt;
&lt;PRE&gt;&amp;lt;ul class="dropdown"&amp;gt;
&amp;lt;li&amp;gt;Lorem ipsum &amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;Ipsum dolor&amp;lt;/li&amp;gt;
...
&amp;lt;/ul&amp;gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using bootstrap 2(HubSpot default) here's a documentation how to do this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://getbootstrap.com/2.3.2/components.html#buttonDropdowns" target="_blank" rel="noopener"&gt;https://getbootstrap.com/2.3.2/components.html#buttonDropdowns&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documentation for bootstrap 3:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://getbootstrap.com/docs/3.4/components/#dropdowns" target="_blank" rel="noopener"&gt;https://getbootstrap.com/docs/3.4/components/#dropdowns&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and for the currently latest bootstrap(4.x):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://getbootstrap.com/docs/4.5/components/dropdowns/" target="_blank" rel="noopener"&gt;https://getbootstrap.com/docs/4.5/components/dropdowns/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here's the idea behind it:&lt;BR /&gt;you create a clickable element(&amp;lt;a&amp;gt;/&amp;lt;button&amp;gt; ...) and by clicking on it it will trigger a (css) animation to display the list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best,&lt;/P&gt;
&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 20:49:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358929#M17823</guid>
      <dc:creator>Anton</dc:creator>
      <dc:date>2020-07-31T20:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Styling select input dropdown</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358939#M17824</link>
      <description>&lt;P&gt;Hi Anton,&lt;BR /&gt;&lt;BR /&gt;I probably should've specific that I'm using hubspot form with &lt;STRONG&gt;Set as raw HTML form&lt;/STRONG&gt; option checked, with shortcode generated by HubSpot plugin for WordPress. I don't need to create a custom dropdown, but rather to modify the one hubspot provides which I managed to do, but the validation doesn't seem to like my solution. Here's the JavaScript code I have written for this problem so you get the idea of what I'm trying to accomplish:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;const styleSelectInputs = _ =&amp;gt; {
	let openedDropdown;

	const openDropdown = e =&amp;gt; {
		const input = e.target;
		const dropdown = input.nextElementSibling;
		dropdown.style.display = 'block';
		openedDropdown = dropdown;
	}

	const closeDropdown = _ =&amp;gt; {
		openedDropdown.style.display = 'none';
	}

	const setSelectValue = e =&amp;gt; {
		e.stopPropagation();
		const selected = e.target;
		const allOptions = [...selected.parentNode.querySelectorAll('.hs-custom-option')]
		
		selected.classList.add('active');
		allOptions.forEach(option =&amp;gt; option !== selected &amp;amp;&amp;amp; option.classList.remove('active'));

		const input = selected.parentNode.previousElementSibling;
		const options = [...input.options];
		let selected_opt, selected_idx;
		options.forEach((option, i) =&amp;gt; {
			if (option.value === selected.dataset.value) {
				selected_opt = option;
				selected_idx = i;
			}
		});

		selected_opt.selected = true;
		input.value = selected_opt.value;
		input.selectedIndex = selected_idx;
		input.classList.remove('invalid');
		input.classList.remove('error');
		
		closeDropdown();
	}

	const createOption = option =&amp;gt; {
		const opt = document.createElement('div');
		opt.setAttribute('class', 'hs-custom-option');
		opt.dataset.value = option.value;
		opt.innerHTML = option.innerHTML;
		opt.addEventListener('click', setSelectValue);

		return opt;
	}

	const stylize = input =&amp;gt; {
		const options = [...input.options];
		const newOptions = options.map(option =&amp;gt; createOption(option));

		const container = document.createElement('div');
		container.setAttribute('class', 'hs-custom-container');
		container.style.display = 'none';
		newOptions.forEach(option =&amp;gt; container.appendChild(option));

		input.insertAdjacentElement('afterend', container);
	}

	const init = _ =&amp;gt; {
		const select_inputs = [...document.querySelectorAll('.hs-form fieldset .hs-form-field .input select.hs-input')]
		select_inputs.forEach(input =&amp;gt; {
			stylize(input);
			input.addEventListener('click', openDropdown);
		})

		document.addEventListener('click', e =&amp;gt; {
			if (e.target.nodeName !== 'SELECT' &amp;amp;&amp;amp; !e.target.classList.contains('hs-input')) {
				closeDropdown();
			}
		})
	}

	init();
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 21:17:17 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358939#M17824</guid>
      <dc:creator>unesic</dc:creator>
      <dc:date>2020-07-31T21:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Styling select input dropdown</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358996#M17839</link>
      <description>&lt;P&gt;Okay.&lt;/P&gt;
&lt;P&gt;So you've done it right by setting it up without adding the HubSpot CSS. But still - you can't technicaly modify the &amp;lt;option&amp;gt; dropdown. It's just not possible since - as I've said before - it will be rendered by the browser/os.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an article which describes this topic in detail (and might help you)&lt;/P&gt;
&lt;P&gt;&lt;A href="https://css-tricks.com/dropdown-default-styling/" target="_blank"&gt;https://css-tricks.com/dropdown-default-styling/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best,&lt;/P&gt;
&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Sat, 01 Aug 2020 20:42:18 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Styling-select-input-dropdown/m-p/358996#M17839</guid>
      <dc:creator>Anton</dc:creator>
      <dc:date>2020-08-01T20:42:18Z</dc:date>
    </item>
  </channel>
</rss>

