Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

addOnKeyPress() browser compatibility

Posted on by 685

Hi Everyone,

I'm facing some problems while executing below script.

Xrm.Page.getControl('telephone1').addOnKeyPress(function () {  /*Code*/  };

In Mozilla Firefox browser it is not working, and same script is working fine with "Chrome" and "Edge" browser.

Is there any browser compatibility issues with Mozilla Firefox browser.

Can i know Mozilla Firefox supports addOnKeyPress() event or not?

Please suggest ways to solve issue?

Thanks,

Hardik Chauhan

*This post is locked for comments

  • chauhanhardik Profile Picture
    chauhanhardik 685 on at
    RE: addOnKeyPress() browser compatibility

    Hi,

    here's whole script, i think there is a problem with Xrm.Page.getControl(keypressphone).getValue().replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');

    control = ["telephone1", ''mobilephone'']

    function PhoneMasking(control) {

       if (control == undefined || control == null) { return; }

       if (typeof (control) == "string") {

           callFormatPhoneNumber(control);

       }

       else if (typeof (control) == "object") {

           for (var iControl = 0; iControl < control.length; iControl++) {

               if (Xrm.Page.getControl(control[iControl]) != null) {

                   callFormatPhoneNumber(control[iControl]);

               }

           }

       }

    }

    callFormatPhoneNumber = function (control) {

       var phone = Xrm.Page.getAttribute(control);

       //To get field label name

       var label = Xrm.Page.getControl(control).getLabel();

       //Formats the phone number to US Format(123-456-7890)

       FormatPhoneNumber(phone, label, control);

       //Formats the phone number to US format as user types

       keypressmasking(control, label);

    }

    function FormatPhoneNumber(number, label, control)

    {

       var BusinessAllNumeric = number;

       var labelValue = label;

       //Check the field exists and is not null

       if (typeof (number) != "undefined" && number.getValue() != null) {

           if (labelValue) {

               BusinessAllNumeric = number.getValue().replace(/[^0-9]/g, "");

               if (BusinessAllNumeric.length == 10 || BusinessAllNumeric.length == 0) {

                   FormattedBusinessNumber = BusinessAllNumeric.substr(0, 3) + "-" + BusinessAllNumeric.substr(3, 3) + "-" + BusinessAllNumeric.substr(6, 4);

                   number.setValue(FormattedBusinessNumber);

                   // To clear form notification

                   Xrm.Page.ui.clearFormNotification(labelValue);

                   // To clear field notification

                   Xrm.Page.getControl(control).clearNotification();

               }

               else {

                   // To set form notification

                   Xrm.Page.ui.setFormNotification(labelValue + " must contain 10 digits.", "WARNING", labelValue);

                   // To set field notiffication

                   Xrm.Page.getControl(control).setNotification(labelValue + " must contain 10 digits.");

               }

           }

       }

    }

    function keypressmasking(keypressphone, label)

    {

       var notificationid = label;

       // check the field exists

       if (typeof (keypressphone) != "undefined")

       {

           //To show form notification on key press events based on conditions

           Xrm.Page.getControl(keypressphone).addOnKeyPress(function () {

               if (notificationid) {

                   var phoneNo = Xrm.Page.getControl(keypressphone).getValue();

                   phoneNo = phoneNo.replace("-", "").replace("-","");

                   if (phoneNo.length == 10 || phoneNo.length == 0) {

                       var formattedPhone = phoneNo.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');

                       Xrm.Page.getAttribute(keypressphone).setValue(formattedPhone);

                       Xrm.Page.ui.clearFormNotification(notificationid);

                       Xrm.Page.getControl(keypressphone).clearNotification();

                   }

                   else {

                       Xrm.Page.ui.setFormNotification(notificationid + " must contain 10 digits.", "WARNING", notificationid);

                       Xrm.Page.getControl(keypressphone).setNotification(notificationid + " must contain 10 digits.");

                   }

               }

           });

       }

    }

    Thanks,

    Hardik Chauhan

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: addOnKeyPress() browser compatibility

    Hi,

    no there is no compability issue. I tested on my CRM environment with firefox and it is working fine.

    Could you please post your entire code?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans