Bruce Stemplewski
Bruce Stemplewski

Reputation: 1343

How can I allow selection of a date using the calendar button but disable typing of date in Dojo Date Textbox?

How can I allow selection of a date using the calandar button but disable typing of date in Dojo Date Textbox?

Is there a way to do this? If so how?

Basically I want the users to be able to select a date using the calendar button but don't allow them to manually enter a date.

Upvotes: 1

Views: 343

Answers (2)

Tim Tripcony
Tim Tripcony

Reputation: 8086

Create a client-side onfocus event:

thisEvent.target.blur();

That doesn't prevent the field's value from being programmatically populated via the date helper, but if they try to manually focus (i.e. click or tab into) the field, it will kick them back out again.

Upvotes: 1

Naveen
Naveen

Reputation: 6936

There is a new property of showReadonlyAsDisabled which I tried on date time field. But it ended up creating a disabled field, but surprisingly it creates a readonly field in case of edit box. So I had to create a workaround by setting the readonly property via javascript while loading the page. Below is the code snippet:

<xp:inputText id="dateTimeField">
    <xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper>
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
</xp:inputText>
<xp:br></xp:br>
<xp:scriptBlock>
    <xp:this.value><![CDATA[XSP.addOnLoad(
    function() {
        document.getElementById("#{id:dateTimeField}").readOnly = true;
    }
);]]></xp:this.value>
</xp:scriptBlock>

I don't know if this is optimal solution, but it works!

Upvotes: 0

Related Questions