Brian
Brian

Reputation: 13571

Is there anyway to disable the client-side validation for dojo date text box?

In my example below I'm using a dijit.form.DateTextBox:

<input type="text" name="startDate" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'MM/dd/yyyy'}"  value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>' />

So for example, if the user starts to enter "asdf" into the date the field turns yellow and a popup error message appears saying The value entered is not valid.. Even if I remove the constraints="{datePattern:'MM/dd/yyyy'}" it still validates.

Without going into details as to why, I would like to be able keep the dojoType and still prevent validation in particular circumstances.

Upvotes: 4

Views: 5464

Answers (3)

esarjeant
esarjeant

Reputation: 553

I had a similar problem, where the ValidationTextBox met all my needs but it was necessary to disable the validation routines until after the user had first pressed Submit.

My solution was to clone this into a ValidationConditionalTextBox with a couple new methods:

    enableValidator:function() {
        this.validatorOn = true;
    },

    disableValidator: function() {
        this.validatorOn = false;
    },

Then -- in the validator:function() I added a single check:

        if (this.validatorOn)
        { ... }

Fairly straightforward, my default value for validatorOn is false (this appears right at the top of the javascript). When my form submits, simply call enableValidator(). You can view the full JavaScript here:

http://lilawnsprinklers.com/js/dijit/form/ValidationTextBox.js

Upvotes: 1

RodeoClown
RodeoClown

Reputation: 13788

Try overriding the validate method in your markup.

This will work (just tested):

<input type="text" name="startDate" dojoType="dijit.form.DateTextBox" 
  constraints="{datePattern:'MM/dd/yyyy'}"  
  value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>'
  validate='return true;'
/>

Upvotes: 6

Nick Berardi
Nick Berardi

Reputation: 54854

My only suggestion is to programmatically remove the dojoType on the server-side or client-side. It is not possible to keep the dojoType and not have it validate. Unless you create your own type that has you logic in it.

Upvotes: 1

Related Questions