flask wtf.quick_form running some javascript and setting a form variable
<p>I am creating blog posts and have so far done it with a normal html form.  One funky think I was doing was running javascript onclick and setting a hidden variable in the form with extra data from the page.  This was passed to the server just fine and gotten with request.form.  Now I want to use wtf.quick_form for the entering of blog posts.  qtf.quick_form works great for simple things, but now I need to run some javascript on click and then set a form variable.  At the server, I need to retrieve this form variable.  Does anyone know how to do this?</p>

<p>As an example, I tried this :</p>

<pre><code>{{ wtf.form_field(form.submit, button_map={'submit':'new_entry_submit_button'}) }}
{{wtf.quick_form(form)}} 
</code></pre>

<p>And then used jquery like this to intercept the submit button :</p>

<pre><code>$(function(){        
    $('#new_entry_submit_button').bind('click', function(e) {        
        x = getSavedAndClickedAsString();
        document.getElementsByName("srcLibArticles").item(0).value =  x; &lt;!--libArStr; --&gt;
        return true
    });
});
</code></pre>

<p>None of this is working not to mention, I can't set  a "hidden" field in the form.  I don't know how to set a field in the form from the page.  That's all handled under the hood.</p>

<p>Edit:</p>

<p>I found a Hidden field type for my form so I am including what my flask form looks like at the server :</p>

<pre><code>class NewEntry(Form):
    '''
        A form for new entries
    '''
    title = TextAreaField("Title", validators=[Required()])
    text = PageDownField("Text", validators=[Required()])
    tags = TextAreaField("Tags", validators=[Required()])
    srcLibEntries = HiddenField("srcLibEntries")
    submit = SubmitField('Submit')
</code></pre>

<p>I am trying to write javascript that updates the hidden field upon submit and sends the updated hidden field back to the server.</p>

<p>Edit2:
I have written the following html and it almost works but there are still some bizzare things happening :</p>

<pre><code>&lt;form  method="post" role="form"&gt;       
    {{ wtf.form_field(form.title) }}
    {{ wtf.form_field(form.text) }}
    {{ wtf.form_field(form.tags) }}
    {{ wtf.form_field(form.srcLibEntries, id="srcLibArticles") }}
    {{ wtf.form_field(form.submit, button_map={'id':'new_entry_submit_button'}) }}
&lt;/form&gt;
</code></pre>

<p>Most noteably, the id of the submit button will not change.  Also, it is creating a label for the hidden input (set to the form variable name) and printing the label.  The hidden input is there, but so is an annoying label which adds text to the page.</p>

<p>Edit 3:</p>

<p>I found out you can set the id of a form field right in python at your forms.py like this.  (Ultimately, this is how I worked my example) :</p>

<pre><code>class NewEntry(Form):
    '''
        A form for new entries
    '''
    title = TextAreaField("Title", validators=[Required()])
    text = PageDownField("Text", validators=[Required()])
    tags = TextAreaField("Tags", validators=[Required()])
    srcLibEntries = HiddenField(label=None, id="srcLibArticles")
    submit = SubmitField('Submit', id="new_entry_submit_button")
</code></pre>