WTForms-Javascript: Pass Onclick To WTF Field
Is there a way to pass 'onclick' onto a WTForm field? I'd like to enable/disable a field depending on whether a WTF checkbox is selected. But the HTML from WTForms does not create
Solution 1:
You need to pass the extra arguments while rendering your form.
{% block content %}
{{ form.checkbox(onchange="doStuff()") }}
{{ form.required() }}
<script>
function doStuff(){
var checked = document.getElementById('checkbox').checked
if (checked){
document.getElementById('required').disabled = true
} else {
document.getElementById('required').disabled = false
}
}
doStuff()
</script>
{% endblock %}
Post a Comment for "WTForms-Javascript: Pass Onclick To WTF Field"