【发布时间】:2018-12-28 12:20:51
【问题描述】:
我正在使用 Flask 和 HTML5 制作情绪分析 UI。在主页 html 页面(使用 render_template 从 Flask 链接)上,我有单选按钮。我有一条自定义消息和一个“必需”设置,因此如果未选择单选按钮并且用户尝试点击“提交”,则会显示一条消息并且用户无法提交。 问题是,如果未选择单选按钮,则消息不会消失,并且即使用户选择了按钮,也不允许用户提交答案。必须刷新页面才能避免这种情况。
如果我删除整个“onvalid”部分并只留下“required”部分,它工作得很好,但是我丢失了自定义消息并且只有一个默认消息。如果有人能帮助我理解为什么会发生这种情况以及如何解决它,我将不胜感激。
提前非常感谢。这是有问题的代码部分(特别是第 4 行):
<form method="post"><center class='sansserif'>
<table>
<tr>
<td><input type="radio" name="sentiment" value=1 oninvalid="this.setCustomValidity('Please select a rating before continuing.')" required="required"> Very negative<br>
</td>
</tr>
<tr>
<td><input type="radio" name="sentiment" value=2> Negative<br>
</td>
</tr>
<tr>
<td><input type="radio" name="sentiment" value=3> Neutral<br></td>
</tr>
<tr>
<td><input type="radio" name="sentiment" value=4> Positive<br></td>
</tr>
<tr>
<td><input type="radio" name="sentiment" value=5> Very Positive
</center></td>
</tr>
<tr><td><br></td></tr>
<tr>
<td><center><input type="checkbox" name="English" value= 'checked'> <em> This sentence is in English</em></center><br></td>
</tr>
<tr>
<td><input class="button" type="submit" value="Submit"/></td>
</tr>
</table>
<br>
</form>
【问题讨论】:
-
你在使用 Flask-WTF 吗?