Either disable or totally change mask in RadMaskTextbox totally in client side

1 Answer 14 Views
MaskedTextBox
Carlo
Top achievements
Rank 1
Carlo asked on 12 May 2021, 03:46 PM

Hello,

We have a zip code entry text box that utilizes radmasktextbox to require entry of zipcode in us format. We'd like to support international postal code standards. I have created some JavaScript that in theory should switch the text box on client side to allow up to 10 of any characters when the nation isn't USA, but its simply not totally changing the text entry formatting. It can get to the point where it prints your characters in the box when you type, but when you blur it will strip out any chars that violate the old rules (US, 5+4). 

Not permitting changing of the mask in clientside easily seems to be a fantastically big oversite. how does one do this? 

code to  change the mask:


       funciton changeFormat(sender, args) {
            var unitedStates = ['US', 'USA', 'UNITED STATES', 'UNITED STATES OF AMERICA'];
            var i = 0;

            var mask = [];
            if (unitedStates.indexOf($find(countryControlId).get_value().toUpperCase()) < 0) {
                for (i = 0; i < 10; i++) {
                    mask[mask.length] = new Telerik.Web.UI.RadFreeMaskPart();
                }
            } else {
                for (i = 0; i < 5; i++) {
                    mask[mask.length] = new Telerik.Web.UI.RadDigitMaskPart();
                }
                mask[mask.length] = new Telerik.Web.UI.RadLiteralMaskPart('-');
                for (i = 0; i < 4; i++) {
                    mask[mask.length] = new Telerik.Web.UI.RadDigitMaskPart();
                }

            }

            $find(zipControlId).set__initialDisplayMasks(mask);
            $find(zipControlId).set__initialMasks(mask);
            $find(zipControlId)._setDisplayMask(mask);
            $find(zipControlId)._setMask(mask);
            $find(zipControlId)._length = 0;
            $find(zipControlId).clear();
}

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 26 May 2021, 01:54 PM

Hello Carlo,

I am afraid the RadMaskedTextBox does not support changing the Mask on the client side. Although some developers have found their way around it, it has its flaws, see Can the mask of a RadMaskedTextBox be changed via javascript? If you like this answer, feel free to use it.

My suggestion is to either have multiple textboxes with different masks and render/display the one that is relevant to the selected State/Country or make sure the page does a PostBack upon selecting a country/state and during the PostBack you will change the Mask on the backend.

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MaskedTextBox
Asked by
Carlo
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or