Open johncarmack1984 opened 7 years ago
Have you tried emptying the select value and triggering a change ?
I couldn't sign up on your demo: null value in column "portfolio" violates not-null constraint DETAIL: Failing row contains (3, null, 11).
Can't see your demo as anonymous: https://dev.stockpicker.io/quandl_wiki/ 'AnonymousUser' object has no attribute 'profile'
Hey there y'all! Here's what I've got.
Running an autocomplete search on a database table of tickers and stock names using a multiple select via django-autocomplete-light.
My aim is to submit the form via AJAX & clear the text box. Instead, what happens is that the form goes through (albeit with some workarounds that are kludgy, see below) but after submission I can't figure out how to get the form to clear. Clearing the form is the real problem, but the submission is wonky too so if there's an obvious solution to that I'm all ears.
Thus far efforts to fix the problem have been focused around getting
allowClear: true
anddata-allow-clear="true"data-allow-clear="true"
into all the right places but so far I haven't figured it out. The solution may be totally unrelated, this is my first attempt at modifying AJAX.AJAX code from this tutorial : Coding for Entrepeneurs: AJAXify Django Forms
I got the AJAX code working perfectly on that tutorial (plain text fields), and I got the autocomplete POST data going through just fine, but combining the form with AJAX, is preventing the multiple-select box from clearing on submit, even when
allowClear
is hard-set totrue
in select2.js.Code:
urls.py
models.py
forms.py
mixins.py
views.py
base.html
ticker_name_pair_form.html
Console output of
$python manage.py runserver
Page load
[21/Aug/2017 08:23:03] "GET /quandl_wiki/ HTTP/1.1" 200 8425
Click on select box, enabling drop down select
[21/Aug/2017 08:24:13] "GET /quandl-wiki-search-autocomplete/?q=tsla HTTP/1.1" 200 96
type search for TSLA, select TSLA : Tesla Motors, Inc.
``
submit form
^ now the above is a problem, because I suspect it means I'm not getting the actual data on the server end even though the client end (google developer tools) says the form is successfully being sent. So I changed
forms.py
to require the 'add_to_portfolio' field and now I'm getting a 400 error.[21/Aug/2017 08:31:40] "POST /quandl_wiki/ HTTP/1.1" 400 49
So the form isn't going through, and I can't figure out what to change where to make it work. Further, even when the client thinks it went through, the box doesn't clear. I've scoured the docs as best I know how but am, for now, stuck. Any ideas?
App is at http://dev.stockpicker.io/quandl_wiki