Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get WTF form object data without a POST request?
    primarykey
    data
    text
    <p>I have a template which allows user to enter search parameter (search.html)</p> <pre><code>{% from "_formhelpers.html" import render_field %} &lt;form method=”post”&gt; &lt;dl&gt; {{ render_field(form. notificationId) }} {{ render_field(form. recordName) }} &lt;/dl&gt; &lt;div id="searchResults" &gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>Macro</p> <pre><code>{% macro render_field(field) %} &lt;dt&gt;{{ field.label }} &lt;dd&gt;{{ field(**kwargs)|safe }} {% if field.errors %} &lt;ul class=errors&gt; {% for error in field.errors %} &lt;li&gt;{{ error }}&lt;/li&gt; {% endfor %} &lt;/ul&gt; {% endif %} &lt;/dd&gt; {% endmacro %} </code></pre> <p>And a template for search results(result.html)</p> <pre><code>{% for notification in content %} Result: content[notification]['type'] }}&lt;/td&gt; {% endfor %} </code></pre> <p>I am using the following ajax request to get search results and display in the above template.The ajax function is called on keyup of both the search fields</p> <pre><code>$.ajax( { url: ‘result’, dataType: "html", data:createQueryString(),// gets the value from the dataFields and creates a queryString success: function(data) { $("# searchResults").html(data); } }); </code></pre> <p>I also I have 2 views one for the searchcriteria section( the section containing the 2 search fields) and one for the search results section.</p> <pre><code>class NotificationSearchView(MethodView): def get(self): searchform = SearchForm() return render_template("search.html”, searchform=searchform) @classmethod def registerSelf(cls, app): NotificationSearchView.app = app app.flaskApp.add_url_rule('/search ', view_func=NotificationSearchView.as_view(‘search’)) class NotificationResultView(MethodView): def get(self): searchform = SearchForm() success, content=self.performSearch(searchform) //search method which takes the search parameters and performs the search return render_template("result.html”, content=content) @classmethod def registerSelf(cls, app): NotificationResultView.app = app app.flaskApp.add_url_rule('/result', view_func= NotificationResultView.as_view(‘result’)) </code></pre> <p>WTF form class</p> <pre><code>from wtforms import Form, TextField class SearchForm(BaseForm): notificationId = TextField(notificationId) recordName = TextField(recordName) </code></pre> <p>The issue which I am facing is that the wtf form object isn’t populated when the ajax call is made to the NotificationResultView, which I believe is because there is no post request fired, but according to my design there is no need of a post request.</p> <p>I have tried by making the ajax request as post request but even then the wtf form object comes back empty.</p> <p>Now my only other option is if I pass the search criteria in the query string when making the ajax call, but not sure if that’s the best approach.Please suggest how to proceed in this case. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload