如何使用dijit / Textarea验证(Dojo 1.9)? [英] How to use dijit/Textarea validation (Dojo 1.9)?

查看:131
本文介绍了如何使用dijit / Textarea验证(Dojo 1.9)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有textarea是必填字段。我发现发表Dojo没有验证Textarea ,但在Dojo 1.9,有一个参数'需要'。



我已经完成了以下工作:

  new Textarea({required:true,value:},query('[name = description]')[0])

但效果不是我预期的。即使该字段没有被聚焦(与例如ValidationTextBox相反),texarea总是具有红色边框。但是当我打电话:

  form.validate()

即使texarea为空,验证也被传递。



是否可以得到Textare与ValidationTextBox中的行为一样,或者现在,该组件的验证尚未准备好,我必须编写自定义版本(如链接的帖子)或等待下一个Dojo?

解决方案

我已经使用SimpleTextArea和ValidationTextArea的mixin:

  define([dojo / _base / declare,dojo / _base / lang,dijit / form / SimpleTextarea,dijit / form / ValidationTextBox $ b function(declare,lang,SimpleTextarea,ValidationTextBox){

return declare('dijit.form.ValidationTextArea',[SimpleTextarea,ValidationTextBox],{
constructor:function(params){
this.constraints = {};
this.baseCla ss + ='dijitValidationTextArea';
},
templateString:< textarea $ {!nameAttrSetting} data-dojo-attach-point ='focusNode,containerNode,textbox'autocomplete ='off'>< / textarea>
})
})

另请参见我的答案文本区域的验证


I have textarea which is required field. I've found post suggesting that Dojo doesn't have validation for Textarea, but in Dojo 1.9, there's an argument 'required'.

I've done the following:

new Textarea({required:true, value:""}, query('[name=description]')[0])

but the effect isn't what I've expected. The texarea has red border always, even if the field wasn't focused (as opposite to, for example, ValidationTextBox). But when I call:

form.validate()

the validation is passed even if the texarea is empty.

Is it possible to get Textare behave the same as in ValidationTextBox, or as for now, the validation for that component is not yet ready and I'd have to write custom version (as in linked post) or wait for next Dojo?

解决方案

I've done it using mixin of SimpleTextArea and ValidationTextArea:

define(["dojo/_base/declare", "dojo/_base/lang", "dijit/form/SimpleTextarea", "dijit/form/ValidationTextBox"],
function(declare, lang, SimpleTextarea, ValidationTextBox) {

  return declare('dijit.form.ValidationTextArea', [SimpleTextarea, ValidationTextBox], {
    constructor: function(params){
      this.constraints = {};
      this.baseClass += ' dijitValidationTextArea';
    },    
    templateString: "<textarea ${!nameAttrSetting} data-dojo-attach-point='focusNode,containerNode,textbox' autocomplete='off'></textarea>"
  })
})

See also my answer in Dojo validation of a textarea

这篇关于如何使用dijit / Textarea验证(Dojo 1.9)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆