views:

1448

answers:

3

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.

A: 

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.

Nick Berardi
+2  A: 

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;'
/>
RodeoClown
why in Buddah's name isn't the `constraints="{datePattern}"` mentioned ANYWHERE in any dojo docs or api's? Thank you sooooo much for this. This has been bugging me for a while now. *tears of joy*
peirix
No idea - I just copied the code from the original post and added the validate method :)
RodeoClown
+1  A: 

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

esarjeant