Flask 如何在WTForms中将值设置为隐藏整数字段

Flask 如何在WTForms中将值设置为隐藏整数字段,flask,flask-wtforms,Flask,Flask Wtforms,我有一个表单,需要取1integervalue。此整数值将是与html表中的行关联的id template.html {% block content %} <div id="formContainer" class="center top"> <p class="lead">Select simulation session </p> {% if simulationSessions %} <table class="table tab

我有一个表单,需要取1
integer
value。此整数值将是与
html
表中的行关联的id

template.html

{% block content %}
<div id="formContainer" class="center top">
  <p class="lead">Select simulation session </p>
  {% if simulationSessions %}
    <table class="table table-striped">
    <thead>
      <tr>
        <th></th>
        <th>#</th>
        <th>Label</th>
        <th>Date</th>
      </tr>
    </thead>
    <tbody>
    {% for simulationSession in simulationSessions %}
      <tr>
        <td><input id="id-{{ simulationSession.id }}" name="idRadio" type="radio" value="{{ simulationSession.id }}"> </td>
        <td>{{ simulationSession.id }}</td>
        <td>{{ simulationSession.label }}</td>
        <td>{{ simulationSession.date.strftime('%d-%m-%y %H:%M') }}</td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  <button type="button" class="btn btn-sm btn-success">Analyse</button>
  {% else %}
    <div class="alert alert-danger" role="alert">
      <strong>Oopsadazy!</strong> No simulations are registered in the database for this user. You need to run a simulation session before analyzing it!
    </div>
  {% endif %} 
</div>
{% endblock %} 
我的问题是,提交表单后,如何从所选单选按钮获取值并将其用作隐藏整数字段的数据

这可以在html中的脚本中使用类似的东西来完成吗?(本文件未编译)

视图的外观如下所示:

view.py

class SimulationSessionSelectionForm(Form):
  simulationSessoinId = IntegerField('simulationSessoinId', validators=[DataRequired()], widget=HiddenInput())
@app.route('/dashboard', methods=['GET', 'POST']) 
@login_required
def dashboard():
  form = SimulationSessionSelectionForm()
  if form.validate_on_submit():
    redirect('/somewhere')
  userkey = models.User.query.filter_by(id = current_user.get_id()).first().userKey
  userSimulationSessions = models.SimulationSession.query.filter_by(userKey = userkey).all()
  simulationSessions = []
  simulationSessionIds = []
  for simulation in userSimulationSessions:
    simulationSessions.append({'id' : simulation.sessionID, 'label' : simulation.label, 'date' : simulation.date})
    simulationSessionIds.append(simulation.sessionID)
  return render_template("dashboard.html", simulationSessions = simulationSessions, form = form)

模板中的此行将隐藏字段(和csfr令牌)添加到

我想只要触发单选按钮更改事件,我就可以通过一些
jquery
脚本设置隐藏的
IntegerField
的值。为此,我使用了以下代码:

<script>
    $( document ).ready(function() {
      $('input[type=radio][name=idRadio]').change(function() {
        $('#simulationSessoinId').val(this.value)       
      });
    });

</script> 

$(文档).ready(函数(){
$('input[type=radio][name=idRadio]')。更改(函数(){
$('#SimulationSessOID').val(this.value)
});
});
{{ form.hidden_tag() }}
<script>
    $( document ).ready(function() {
      $('input[type=radio][name=idRadio]').change(function() {
        $('#simulationSessoinId').val(this.value)       
      });
    });

</script>