动态改变约束
我有一个 dijit.form.NumberTextBox 输入字段,以这些参数开头:
new dijit.form.NumberTextBox({
id: din1,
style: "width:60px",
constraints: {
places: 0,
pattern: '######'
}
},
din1);
一切都很好。我的问题是我想动态更改“位置”和“模式”参数。所以我写这个来改变'places'和'patterns'参数:
var myFldObj = dijit.byId(din1);
if (myFldObj) {
var myConstObj = myFldObj.attr('constraints');
if (myConstObj) {
myConstObj.places = 2;
myConstObj.pattern = '#####.0';
}
}
所以,在我再次显示表单后,我希望输入字段允许2个小数位,但表单仍然像places=0和pattern='#一样#####'。当我检查“places”和“pattern”的值时,我得到了我所期望的结果(2 和 #####.0)。我的问题:
你能即时更改这些值吗?
或者
您是否必须销毁原始 dijit 对象并使用新参数重新创建?
谢谢!!
I have a dijit.form.NumberTextBox input field that starts out with these parms:
new dijit.form.NumberTextBox({
id: din1,
style: "width:60px",
constraints: {
places: 0,
pattern: '######'
}
},
din1);
Everything works great..My question is I would like to change 'places' and 'pattern' parms on the fly. So I wrote this to change 'places' and 'patterns' parms:
var myFldObj = dijit.byId(din1);
if (myFldObj) {
var myConstObj = myFldObj.attr('constraints');
if (myConstObj) {
myConstObj.places = 2;
myConstObj.pattern = '#####.0';
}
}
So, after I show the form again, I'd expect the entry field to allow 2 decimal places but the form still acts like places=0 and pattern='######'. When I check the values of 'places' and 'pattern' I get what I'd expect (2 and #####.0). My question:
Can you change these values on the fly??
OR
Do you have to destroy the original dijit object and recreate with new parms??
Thx!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,这对我有用:
首先,我认为这是一个错误,因为像这样开始的输入字段
然后使用如下代码动态更改:
注意:ntbArry - 绑定到的 dijit.form.NumberTextBox 对象的数组一个html
输入标签 ID。
与以这种方式创建的字段不表现出相同的行为(没有动态约束模式):
它的行为很接近,但每次您键入小数点时,都会弹出错误消息,指出输入无效。在最初使用约束 place=2 和模式“#####.0#”创建的字段上键入小数点时,不会弹出此消息。
因此,为了获得我想要的原始行为:
fieldIDEvents 是与 NumberTextBox 字段关联的 dojo 事件数组。
在继续断开 dojo 事件之前
,然后销毁 NumberTextBox dojo 对象
接下来,将输入标记放回到 html 中,因为它会被破坏:
注意:tdtag 和 html td 标记上的 id 应包含输入标记。
现在,再次创建 NumberTextBox 对象:
这是一些额外的步骤,但是,至少我知道这对我有用......如果我缺少一些基本的东西,请告诉我,很容易错过这些东西的小细节。
So, here is what worked for me:
First, I think this is a bug because an input field that starts out like
that is then changed on the fly with code like:
NOTE: ntbArry - Array of dijit.form.NumberTextBox objs tied to a html
input tag id.
Does not exhibit the same behavior as a field created this way (no constraints mods on the fly):
It's close in behavior but every time you type a decimal point, the error message pops up stating invalid entry. This message doesn't pop up when typing the decimal point on a field that was originally created with the constraints places=2 and pattern '#####.0#'.
So, to get original behavior I wanted:
fieldIDEvents is an array of dojo events tied to NumberTextBox fields.
Before continuing disconnect dojo events
then destroy the NumberTextBox dojo objects
Next, place the input tag back into the html because it gets destroyed:
NOTE: tdtag and an id on a html td tag which should contain the input tag.
Now, create the NumberTextBox object again:
It's a few extra steps but, at least I know this is what works for me..If I'm missing something basic, let me know, it's easy to miss the small details with this stuff.
我使用 Dojo 1.3,我可以看到 dijit.form.NumberTextBox 没有
pattern
和places
属性,但有editOptions
属性。所以我会尝试改变这样的约束:I use Dojo 1.3 and I can see that dijit.form.NumberTextBox has no
pattern
andplaces
properties, but haseditOptions
property. So I would try to change the constraints like this: