Disabling manual input in dijit.form.DateTextBox

10,955

Solution 1

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.

Solution 2

The code below can be used to make DateTextBox read only:

<input data-dojo-type="dijit/form/DateTextBox" 
       data-dojo-id="effectiveDate" 
       type="text" 
       name="effectiveDate" 
       id="effectiveDate" 
       data-dojo-props="'readonly': 'readonly'"/>

Solution 3

@Sudhir : if you set the widget to disabled then you can't select a date on the calendar either.

Try this :

dojo.ready(function(){
    dojo.connect(dijit.byId("yourcalendarid"), "onKeyPress", function(evt){
        dojo.stopEvent(evt);
    });             
});
Share:
10,955
Olivier Tremblay
Author by

Olivier Tremblay

I'm just some kind of weird zombie programmer from the late fourties, born in the mid-eighties. Don't ask. I've got a wife and 2 kids, and I'll be using this forum to provide myself and others with knowledge, mine or otherwise, obtained through brain eating or otherwise.

Updated on July 28, 2022

Comments

  • Olivier Tremblay
    Olivier Tremblay almost 2 years

    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?

    Thanks.