Dojo 验证文本区域
我是第一次尝试使用 dojo,所以这可能是显而易见的。
我有一个非常简单的表单,其中有一个需要填写的文本区域。
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.3/dojo/dojo.js"></script>
<form id='form1' action="" method="" dojoType="dijit.form.Form">
<label for="dob">desc:</label>
<textarea class='multilinecontrol' dojoType="dijit.form.Textarea" selected='true' required='true'></textarea>
<button type='submit' id="next" name="next" dojoType="dijit.form.Button">
Next</button>
</form>
我添加了“必需”属性,因此我可以确保表单在用户继续操作之前有效。
然而,当表单显示时,文本区域周围有一个红色焦点环,其他小部件都没有像这样的行为,这真的很烦人。
知道如何摆脱它吗?
我可以通过放入某种默认文本(例如“将东西放在这里”)来破解它,但随后我必须做额外的验证工作 - 我目前不知道该怎么做。
I'm attempting to use dojo for the first time, so this may be be obvious.
I have a very simple form with one textarea in it that needs to be filled in.
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.3/dojo/dojo.js"></script>
<form id='form1' action="" method="" dojoType="dijit.form.Form">
<label for="dob">desc:</label>
<textarea class='multilinecontrol' dojoType="dijit.form.Textarea" selected='true' required='true'></textarea>
<button type='submit' id="next" name="next" dojoType="dijit.form.Button">
Next</button>
</form>
I've added the 'required' property, so i can ensure the form is valid before the user can proceed.
However when the form is show the textarea has a red focus ring around it, None of the other widgets behave like this and its really annoying.
Any idea how to get rid of it?
I could hack it by putting some kind of default text in like 'Put stuff here' but then I have to do extra validation work - which I presently can't work out how to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不用复制整个现有的类,使用 mixin 就足够了:
不幸的是,我无法使用红色感叹号获得与验证输入完全相同的行为 - 由于 Textarea 调整大小功能,所以我完成了 CSS 技巧:
需要将 error.png 从 claro 主题复制到您的 css 位置。它显示在文本区域内部,而不是外部,但这是唯一的、很小的区别。
Instead of copying the whole existing classes, it's enough to use mixin:
Unfortunatelly, I wasn't able to get exactly the same behaviour with red exclamation sign as with validating input - because of Textarea resizing factility, so I've done the CSS trick:
The error.png needs to be copied from claro theme to your css location. It is displayed inside the text area, not outside it, but it's the only, quite minor difference.
这是我的 SimpleValidationTextArea。基本上我已经合并了 dijit/form/ValidationTextBox 和 dijit/form/TextArea。这段代码很丑陋,需要一些改进,但它可以工作;)
Here is my SimpleValidationTextArea. Basically I've merged dijit/form/ValidationTextBox and dijit/form/TextArea. This code is ugly and needs some improvements but it works ;)
我的方法与前两个答案略有不同,但希望更简洁,因为它不涉及编写任何验证代码。
开箱即用的 dijit/form/SimpleTextarea 通过用
我的解决方案只是通过扩展 ValidationTextBox 来定义一个新的文本区域 Dijit。
也就是说,从 SimpleTextarea 获取源代码(90 行和大部分注释),并将 TextBox 替换为 ValidationTextBox。还要覆盖默认的正则表达式模式 (.*) 以允许换行符。
基于SimpleTextarea.js.uncompressed.js
My approach is slightly different to the previous two answers but it is hopefully more concise as it does not involve writing any validation code.
The out of the box dijit/form/SimpleTextarea extends a TextBox by replacing the control with a <textarea>
My solution just defines a new text area Dijit by extending a ValidationTextBox.
That is, take the source from SimpleTextarea (90 lines and most of it comments) and replace TextBox with ValidationTextBox. Also override the default regex pattern (.*) to allow new line characters.
Based on SimpleTextarea.js.uncompressed.js
dijit.form.Textarea
不进行任何验证。这是一个自定义的 ValidationTextArea,供遇到相同问题的任何人使用:dijit.form.Textarea
doesn't do any validation. here is a custom ValidationTextArea for anybody facing the same issue:根据您的问题,我猜您正在使用 dojo 1.6
这是我的
ValidationTextarea
。它使用 SimpleTextArea 支持“行”和“列”,并使用 ValidationTextBox 进行验证。这个想法与另一个答案类似,只是在这种情况下我没有为小部件定义
templateString
。Based on your question, I guess you are using dojo 1.6
This is my
ValidationTextarea
. It uses SimpleTextArea to support 'row' and 'cols' and ValidationTextBox for validation stuff.The idea is similar to another answer just that in this case I don't define a
templateString
for the widget.