javascript - Dynamic select menu not working after change event -
im trying create dynamic select menu select client , filter contacts customer.
when select client filters contacts client select menu not show selected.
<template name="newleadform"> <form id="lead"> <fieldset> <legend>new lead</legend> <br/> <select id="customer_id" class="span12"> <option id="null" value="null">select one</option> {{#each customers}}<option id="{{id}}" value="{{_id}}">{{name}} - {{city}}, {{state}} {{zip}}</option>{{/each}} </select> <select id="contact_id" class="span12"> <option id="null" value="null">select one</option> {{#each contacts}}<option id="{{id}}" value="{{_id}}">{{first_name}} {{last_name}}</option>{{/each}} </select> <input id="submit" type="submit" class="btn"> </fieldset> </form> </template>
here info beingness supplied template
template.newleadform.customers = function () { homecoming customers.find(); }; template.newleadform.contacts = function () { console.log(session.get("_customer_id")); homecoming contacts.find({customer_id: session.get("_customer_id")}); };
and event handlers
template.insert.events({ 'change form#lead #customer_id' : function (event) { client = $("form#lead #customer_id").val(); session.set("_customer_id", $("form#lead #customer_id").val()); }, 'submit form#lead' : function (event) { if (event.type === 'click' || event.type === 'submit') { event.preventdefault(); var customer_id = $("#customer_id").val(); var contact_id = $("#contact_id").val(); var lead_source_id = $("#lead_source_id").val(); var lead_number = $("#lead_number").val(); if(leads.insert({id: leads.find().count() + 1, customer_id: customer_id, contact_id: contact_id})) { $("#customer_id").val(null); $("#contact_id").val(null); session.set("_customer_id", null); } } } });
after meteor re-renders alternative elements in select element, should tell set selectedindex
property on select element updates. can rendered
event:
template.newleadform.rendered = function() { $("#customer_id")[0].selectedindex = 5; // perchance track index know set }
javascript meteor
No comments:
Post a Comment