简体   繁体   English

KnockoutJS和HTML5必需属性且可见:否

[英]KnockoutJS & HTML5 Required Attribute & Visible: No

In my form, the user can toggle the visibility of certain form elements using Knockout in order to save space. 在我的表单中,用户可以使用Knockout切换某些表单元素的可见性,以节省空间。 If the elements are visible and the user has not filled out the required fields, when they press the save button, HTML5 will notify the user of the required fields. 如果元素可见,并且用户尚未填写必填字段,则当按下保存按钮时,HTML5将通知用户必填字段。 However, when the elements are hidden, the save silently fails in that pressing the button does nothing. 但是,当元素被隐藏时,保存操作将静音,因为按下按钮不会执行任何操作。

The only indication to the user that something is wrong is that the save button does not respond. 唯一向用户指示出问题的地方是保存按钮没有响应。 Of course in the console it has the familiar message 'An invalid form control is not focusable'. 当然,在控制台中,它具有熟悉的消息“无效的表单控件不可聚焦”。

Have you dealt this with issue before? 您以前处理过这个问题吗? How did you address it? 您是如何解决的? I don't want to take away the required attribute. 我不想删除必需的属性。 I suppose that one solution could be to validate with JavaScript for those types of fields instead of HTML5. 我想一种解决方案可能是使用JavaScript验证这些类型的字段,而不是HTML5。 Suggestions are appreciated. 建议表示赞赏。

Similar question: 类似的问题:

use form submit instead of read value from selector. 使用表单提交而不是从选择器读取值。 because HTML5 required filed will work if form get submitted. 因为如果提交表单,则必须提交HTML5即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM