views:

260

answers:

2

We have a form that has a text input box it. The data entered into this field generally has no validation (other than being required), but we want it to validate to date if another form equals a certain value. Think about setting up password hints... You choose a hint type, say your dogs name which has no real validation, or you choose your birthday for a hint type in which case we want the field to have date validation...

$(#HNT_1) is 5 for birthday hint type... Now I just want to change the field #HNT_1_TE to go from free-form text to date validation...

I am using the form validation plugin...

Edit: I fixed it... I added an onchange handle to the select box that controlled the hint type, I checked if it's selected value was 5, if so I used the 'rule add' functionality of the validation module to add a date:true rule, if it wasn't, I used rule date:false.

A: 

I know this is a different approach than your method, but you should check out the jQuery Validation plugin.

I've used it in the past to do exactly what you're describing (in my case, I had a set of text fields that were related to some radio buttons; choosing any one radio button activated its corresponding text field's validation settings).

ABach
I'm using the validation plugin...
Brad
I see - my particular example checks whether something is required, not whether it is a particular type (such as a date). Sorry.
ABach
+1  A: 

I added an onchange handle to the select box that controlled the hint type, I checked if it's selected value was 5, if so I used the 'rule add' functionality of the validation module to add a date:true rule, if it wasn't, I used rule date:false.

Brad
Did this work? This is pretty much what I was eluding to in my comment above but in a more jQuery route.
gurun8
@gurun8, yes, it worked, thanks so much for your input...
Brad