如果选中复选框,Python Flask wtforms将禁用表单输入字段



我正在努力让它发挥作用。

我有一个python烧瓶表单,它有一个复选框和一个输入字段。如果勾选了复选框,我想禁用输入字段。我试过在HTML模板中使用脚本,但它似乎不起作用,所以我不确定我做错了什么。

<div class="mb-3">
{{ rent_add_form.full_amount_received.label }}
{{ rent_add_form.full_amount_received }}
</div>
<div class="mb-3">
{{ rent_add_form.amount_received.label}}
{{ rent_add_form.amount_received }}
</div>

fullamountreceived是复选框,amountreceive是输入字段。

在HTML页面的底部,我得到了以下脚本

<script>
function myFunction() {
console.log
// Get the checkbox
var checkBox = document.getElementById("full_amount_received");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
document.getElementById("amount_received").disabled = true;
} else {
document.getElementById("amount_received").disabled = false;
}
}
</script>

如果我在开发人员工具上签入chrome,ID与我指定的ID匹配,但在选中或取消选中该框时,控制台不会显示任何内容。

我发现了这一点,我必须将render_kw={"onclick&":"disableTextBox(("}添加到form.py文件中表单字段的属性中

最新更新