template7 icon indicating copy to clipboard operation
template7 copied to clipboard

How to Assign The Select Element Value In a Loop

Open lifeelement opened this issue 6 years ago • 2 comments

How do you achieve efficiently assigning the selected value to a dynamically loaded dropdown select element while looping in Template7?

lifeelement avatar Dec 17 '18 17:12 lifeelement

I need too =/

guilhermelirio avatar Jul 26 '19 01:07 guilhermelirio

Resolved!!

.js file Template7.registerHelper('select', function (value, options) { var $el = $('<select />').html(options.fn(this)); $el.find('[value="' + value + '"]').attr({ 'selected': 'selected' }); return $el.html(); });

.html file

<select name="uf">
{{#select cliente.uf}}
<option value="0" selected>Selecione</option>
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="PB">Pernanbuco</option>
...
</select>

guilhermelirio avatar Jul 26 '19 20:07 guilhermelirio