I have forms in flask like so:
class form1(Form):
count1=IntegerRangeField('count1')
count2=IntegerRangeField('count2')
class form2(Form):
Incoming=FormField(form1)
Outgoing=FormField(form1)
In the template, I render the fields, with a loop which runs a macro depending on the field type:
{% 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 %}
The macro does not display the slider integer chosen for IntegerRangeFields (macro) but the fields do render on the page. How can I get IntegerRangeFields underlying FormFields to apply the macro?
note: if I used IntegerRangeFields directly in place form FormField, it works.
答案 0 :(得分:0)
这个问题实际上是访问&#39;子表单中的基础字段。而不是FormField本身。
我们可以通过以下方式将宏应用于count1
和count2
{% for field in form.Incoming.form %}
{{field(min=0, max=25, oninput="updateRangeInput(this)")}}
<output><script> document.write() </script > </output>
{% endfor %}