meteor - How can I use autoform to populate a select element with #each? -


here part of form i'd convert using autoform.

<div class="col-lg-4 col-md-4 col-sm-4"> <label for="pay_with" id="pay_with_label">pay with</label> <select name="pay_with" id="pay_with" class="form-control select select-primary mbl" required data-placeholder="select option">     <option value="card">new card</option>     <option value="check">new bank</option>     {{#each device}}         <option value="{{card_id}}" selected {{selected}}>{{brand}} - {{last4}}</option>     {{/each}} </select> 

in autoform, how translate part?

{{#each device}}     <option value="{{card_id}}" selected {{selected}}>{{brand}} - {{last4}}</option> {{/each}} 

create template helper function returns options array select menu, mapping devices array , adding in options in order proper schema autoform, so:

template.myform.helpers({    deviceoptions: function() {        var deviceopts = devices.map(function(device) {          return { label: device.brand+' - '+device.last4, value: device.card_id }       });        deviceopts.unshift({ label: 'new bank', value: 'check' });       deviceopts.unshift({ label: 'new card', value: 'card' });        return deviceopts;    }, }); 

then, can call helper in template directive:

{{> affieldinput name="paywith" type="select" options=deviceoptions }} 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -