TinyMCE 和 HTML5 表单验证
我在 Rails 应用程序中使用 TinyMCE。在我的表单中,我有一个带有 TinyMCE 的“描述”字段,并且该字段对于表单验证是必需的。
但是,当我尝试提交表单时,由于 HTML5 表单验证的原因,我无法提交表单。我的浏览器(Chrome 和 Firefox)告诉我该字段为空。我还有另一个问题。当 Chrome 显示空字段的对话框时,它出现在我的页面顶部,而不是靠近我的表单字段。
I'm using TinyMCE in a Rails application. In my form, I have a "description" field with TinyMCE and this field is mandatory for the form validation.
But when I try to submit my form, I can't, because of the HTML5 form validation. My browser (Chrome and Firefox) tells me that the field is empty. And I have another problem. When Chrome displays the dialog for the empty field, it appears on the top of my page, not near my form field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FF 显示所需 fileld 的气泡,但在错误的位置,Chrome 会抛出错误,因为它找不到显示气泡的字段。所以我的解决方案是禁用 TinyMCE 设置的 display:none 样式,并减小字段大小并使其可见隐。这样,浏览器将在该字段旁边显示气泡,因为该字段位于 TinyMCE 编辑器旁边,用户将知道缺少哪些必填字段。
FF show up a bubble for required fileld but at wrong place, Chrome throws an error because it can't find field to show bubble.. So my solution is disable display:none style set by TinyMCE and reduce the field size and make its visibility hidden. this way browser will show bubble next to this field as this field is next to TinyMCE editor user will know what required field is missing.
我在文本区域中使用了“oninit”选项并工作:
您可以尝试使用 onChange 事件,但它在 Firefox 中无法正常工作。
我的完整代码:
I used the "oninit" option in the textareas and worked:
You could try to use onChange event, but it doesn't work properly in Firefox.
My complete code:
我拿了 @lucaswxp 代码并对其进行了一些更改,因为 Firefox 抛出了一个错误($this.is 不是一个函数,如果我没记错的话)。
此外,我还将其触发代码的方式从: 更改
为:
完整代码:
非常感谢创建者,它的工作方式就像奇迹一样:)
I took @lucaswxp code and changed it a bit, because Firefox was throwing an error ($this.is not a function, if I recall it correctly).
Also I changed the way it fires the code from:
to:
Full code:
Many thanks to the creator, it worked like wonder :)