'How can I set the selected value of a dropdown using a smarty variable
I have a list of suppliers and a defaultSupplier assigned to a template, I add the suppliers to a dropdown and iterate through them using a foreach and I try to make the default selected value depending on the defaultSupplier like this:
<select name="supplier_id" id="supplier_id" class="selectpicker" data-live-search="true" data-width="100%" data-show-tick="false">
<option value="" {if $defaultSupplier eq ""}selected="selected"{/if}>-- {"Choose a supplier"|t} --</option>
{foreach $suppliers as $s}
<option value="{$s.supplier_id}" {if ($defaultSupplier == $s.supplier_name)}selected="selected"{/if}>{$s.supplier_name}</option>
{/foreach}
</select>
But it doesn't work, I get the "Choose a supplier" option selected then I have to manually select my supplier from the dropdown
Solution 1:[1]
I had to close the page and navigate on it again and it worked
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user3848412 |