I have a select with an AlpinheJS @change event that changes the path based on the selected option:
<select role="menu"
id="LanguageSelector"
@change="location.pathname = '/' + $event.target.value + '{{ request.path }}'.slice(3)">
</select>
I want to use this select in another page where I don't want the @change to work:
{% include "shop/components/layout/header/language_selector.html" with enable_onchange=False %}
But I can't figure it out.
I've modified the select in any way I knew, but nothing works:
<div x-data="{ shouldChange: `{{ enable_onchange|default:True }}` }">
{#{% with should_change=enable_onchange|default:True|yesno:"true,false" %}#}
{# <div x-data="{ shouldChange: '{{ should_change }}' }">#}
{#{% endwith %}#}
<select role="menu"
id="LanguageSelector"
{% if enable_onchange|default:True %}@change="location.pathname = '/' + $event.target.value + '{{ request.path }}'.slice(3)"{% endif %}>
{# @change="shouldChange ? location.pathname = '/' + $event.target.value + '{{ request.path }}'.slice(3) : void(0)">#}
</select>
</div>
I've commented out the alternative method I attempted.
@change fires no matter the code.
But if I modify default to False then @change won't work.
So it seems that I don't receive enable_onchange from {% include "shop/components/layout/header/language_selector.html" with enable_onchange=False %} ?
I don't want to use <script> tags.
What do you think ?