javascript 在 dijit.form.DateTextBox 中禁用手动输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8376607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disabling manual input in dijit.form.DateTextBox
提问by Olivier Tremblay
I want to only have the calendar to specify my textbox input, and not permit keyboard-punched numbers in my calendar textbox, inside dijit.form.DateTextBox. Is there any way to do that?
我只想让日历来指定我的文本框输入,并且不允许在我的日历文本框中的键盘输入数字,在 dijit.form.DateTextBox 中。有没有办法做到这一点?
Thanks.
谢谢。
回答by Chandra Prakash
The code below can be used to make DateTextBox
read only:
下面的代码可用于使DateTextBox
只读:
<input data-dojo-type="dijit/form/DateTextBox"
data-dojo-id="effectiveDate"
type="text"
name="effectiveDate"
id="effectiveDate"
data-dojo-props="'readonly': 'readonly'"/>
回答by Philippe
@Sudhir : if you set the widget to disabled then you can't select a date on the calendar either.
@Sudhir :如果您将小部件设置为禁用,那么您也无法在日历上选择日期。
Try this :
试试这个 :
dojo.ready(function(){
dojo.connect(dijit.byId("yourcalendarid"), "onKeyPress", function(evt){
dojo.stopEvent(evt);
});
});
回答by Olivier Tremblay
I actually ended up using something else - here is my solution:
我实际上最终使用了其他东西 - 这是我的解决方案:
dojo.addOnLoad(function () {
dojo.query(".dijitDateTextBox input[role='textbox']").forEach(function (node, index, arr) {
node.setAttribute('readonly', 'readonly');
});
});
By setting the elements I needed to "readonly", I get the desired effect. I execute this on my page loads, I'm not sure about the overhead, but the main point is, it works.
通过将我需要的元素设置为“只读”,我得到了想要的效果。我在我的页面加载时执行这个,我不确定开销,但重点是,它有效。
回答by Sudhir Bastakoti
You could add disabled parameter to your input:
您可以在输入中添加禁用参数:
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'MM/dd/yyyy'}" value='' disabled validate='return true;' />
Hope it helps
希望能帮助到你
回答by cabaji99
Updating the answer from MrZombie in the extended widget you can add:
在扩展小部件中更新 MrZombie 的答案,您可以添加:
//to disable input from user at the textbox.s
startup:function(){
this.inherited(arguments);
dojo.connect(this, "onKeyPress", function(evt){
dojo.stopEvent(evt);
});
},
At the startup of the widget.
在小部件启动时。
回答by cabaji99
There are two options that you can use to disable the dojo date input element.
有两个选项可用于禁用 dojo 日期输入元素。
Code
代码
1) Use the setDisabled(true)
method
1)使用setDisabled(true)
方法
dijit.byId('id').setDisabled(true);
or
或者
2) Set disable
the property directly. (You'll need to disable both elements)
2)disable
直接设置属性。(您需要禁用这两个元素)
dijit.byId(id).disabled = true;
dijit.byId(id).textbox.disabled = true;