views:

701

answers:

1

I have a dropdown and a RadMaskedTextBox on a form. I want the mask applied to the RadMaskedTextBox to be determined by the selected value of the dropdown. Is there any way to do so via javascript? I know I could do a simple postback, but I would prefer not to.

Thanks!

A: 

You can try using the undocumented _SetMask function on your client-side RadMaskedTextBox instance, along with the various mask parts (also available on the client, although under slightly different names):

var mask = [
    new RadDigitMaskPart(), // Digit
    new RadLiteralMaskPart('-'), // dash
    new RadEnumerationMaskPart('Mon|Tue|Wed|Thu|Fri'.split('|')), // Week days
    new RadNumericRangeMaskPart(0, 255), // number between 0-255 incl.
    new RadLowerMaskPart(), // lowercase letter a-z
    new RadUpperMaskPart(), // uppercase letter A-Z
    new RadFreeMaskPart()   // accepts any character
];
RadMaskedTextBox1._SetMask(mask);

The problem you're going to run into is that the mask parts are not translated to their respective display prompt in the client right away. For the above mask it would be ("_-Mon000__"). It seems to wait until blur of the field before rendering the prompt in the browser.

Regardless, the text box will respond appropriately to keystrokes according to the rules set out by the mask above.

Crescent Fresh
Thanks for providing the work around! It is definitely a good idea for Telerik to add a client-side API for changing masks on the fly. I have notified the RadInput product team and they will investigate shortly.
Todd