python - jQuery autocomplete doesn't want to send particular POST data -
i'm trying add item (fund). autocomplete succeeds in showing funds. should retrieve fund.id corresponding 'fund'. if set of eyes on this, appreciated...
just clear: i'm not getting specific error. view redirects if there no 'fund' in post. i'm trying figure out why autocomplete isn't posting fund post value' (fund.id).
-- thank advance
template:
<script type="text/javascript" src="{{ static_url }}js/autocomplete/add_fund_autocomplete.js"></script> ... <form method="post" action="/profile/edit/"> {% csrf_token %} <input type="hidden" name="fund" id="id_fund" /> <div class="inline-block"> <label for="id_omnibox">fund</label> <input id="id_omnibox" name="omnibox" placeholder="enter fund name or search existing..." type="text" /> </div> <div class="input-prepend inline-block"> <label for="id_amount">allocation</label> <span>$</span> <input id="id_amount" name="amount" type="text" placeholder="enter amount" /> </div> <button class="add" type="submit" name="add_position">add</button> </form> add_fund_autocomplete.js:
$(document).ready(function() { $.get('/autocomplete/funds/', function(data) { var completions = new array(); var dict = json.parse(data, function(key, value) { completions.push(key); return value; }); $('#id_omnibox').autocomplete({ source: completions, minlength: 2, select: function(event, ui) { $('#id_fund').val(dict[ui.item.value]); } }); }); }); (autocomplete)view:
@login_required def funds(request): funds = fund.objects.exclude(name='placeholder') result = {} fund in funds: result[fund.name] = str(fund.id) return httpresponse(json.dumps(result)) for example: adding fund hoth ltd amount of $123. hoth ltd's fund.id should 1.
post data
post --------------------------------------------------------- variable value --------------------------------------------------------- fund u'' #empty? :\ csrfmiddlewaretoken u'436f77eb2023043be2f5242bb0443d80' omnibox u'hoth ltd' amount u'123' add_position u'' #just trigger used in view
the variable dict undefined when select callback function called.
you can use ui.item.value.
Comments
Post a Comment