代码之家  ›  专栏  ›  技术社区  ›  machump

将宏应用于Flask FormField

  •  0
  • machump  · 技术社区  · 8 年前

    我在烧瓶里有这样的表格:

    class form1(Form):
        count1=IntegerRangeField('count1')
        count2=IntegerRangeField('count2')
    
    class form2(Form):
        Incoming=FormField(form1)
        Outgoing=FormField(form1)
    

    在模板中,我使用循环渲染字段,循环根据字段类型运行宏:

    {% macro render(form) %}
    <script type='text/javascript'>
    function updateRangeInput(elem) {
      $(elem).next().val($(elem).val());
    }
    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <body>
    {% if field.type in ["IntegerRangeField","FormField"] %}
    {{field.name}}
    {{field(min=0, max=25, oninput="updateRangeInput(this)")}}
    <output><script> document.write() </script > </output>
    {% else %}
    </body>
    {% endmacro %}
    

    该宏不显示为IntegralErrangeFields(宏)选择的滑块整数,但字段会在页面上呈现。如何让FormFields下面的IntegralErrangeFields应用宏?

    注意:如果我直接在FormField表单中使用IntegralErrangeFields,它就可以工作了。

    1 回复  |  直到 8 年前
        1
  •  0
  •   machump    8 年前

    这个问题是实际访问“子窗体”中的基础字段,而不是窗体字段本身。

    我们可以将宏应用于 count1 count2 通过:

    {% for field in form.Incoming.form %}
    {{field(min=0, max=25, oninput="updateRangeInput(this)")}}
    <output><script> document.write() </script > </output>
    {% endfor %}