Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Assign The Select Element Value In a Loop #56

Open
lifeelement opened this issue Dec 17, 2018 · 2 comments
Open

How to Assign The Select Element Value In a Loop #56

lifeelement opened this issue Dec 17, 2018 · 2 comments

Comments

@lifeelement
Copy link

lifeelement commented Dec 17, 2018

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

@guilhermelirio
Copy link

I need too =/

@guilhermelirio
Copy link

guilhermelirio commented Jul 26, 2019

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants