Monday, June 14, 2010

CRM 4.0 Formatting Form Fields

The following is an intuitive Mask/UnMask JavaScript object. If you’re looking to toggle other clients (other than an entity form) you might use it as a template for a server side plug-in. The object makes it easy to enforce various types of formatting such as phone numbers , a social security number, credit card numbers and many more. The sample below formats the account Main and Other phone fields.

When a user gives focus to a phone field the object unmasks the field’s value leaving only numbers (the original user input) or blank. Once focus is lost the mask is applied again, if a value exists, giving it its final display. The object also fires when the form is saved to support a situation where focus is not fired i.e. when the user uses the keyboard to save the record.

There’re also other features such as displaying the format as a title or telling the mask to fire when the form loads. The later is hardly required but you might find it useful to leverage the user interaction with the form … and cleans/reformat imported/external values along the way.

If you take a closer look you’ll notice that the object receives both a format (mask) such as “(##) ###-####” and a regular expression which is an unmask filter e.g. “\\D”. “\\D” means anything but numbers which is what you need to remove/replace to get the user’s original input.

The code goes in the account entity onload event.
Give it a go and feel free to leave comments.



function Mask(format)
{
var m = this;

/* e.g. (##) ###-#### */
m.Format = format;
m.Field = null;
/* OnLoad - Might be Used to cleans imported values. */
m.OnLoad = false;
/*
A regular expression for unwanted (bad) characters.
e.g. A field (e.g. phone number) original (before formatting) characters must contain numbers only.
*/
m.Filter = null;

var onloadbound = false;
var onsavebound = false;
var onfocusbound = false;

m.Mask = function()
{
if (!m.Field)
{
return alert("Mask is missing a field");
}

/* Sets the textbox title to required Format */
m.Field.title = m.Format;

if (!onfocusbound)
{
onfocusbound = m.Field.attachEvent("onfocusin", unmask);
m.Field.attachEvent("onfocusout", mask);
}

if (m.OnLoad && !onloadbound)
{
onloadbound = mask() == undefined;
}

if (!onsavebound)
{
onsavebound = crmForm.attachEvent("onsave",mask);
}
}

function unmask()
{
m.Field.DataValue = strip();
}

function mask()
{
/* Reformat */
var formated = m.Format;
/* value as Array of characters */

var splitValue = strip().split("");

if (splitValue.length == 0)
{
m.Field.DataValue = null;
return;
}

/* Regex defining a single placeholder */
var placeHolderReg = new RegExp("#{1}");
/* Replace each placeholder with a single character */
for(var i = 0; i < splitValue.length ; i++)
{
formated = formated.replace(placeHolderReg,splitValue[i]);
}

m.Field.DataValue = formated;
}

function strip()
{
if (!m.Field.DataValue)
{
return "";
}
/* Strip field from unwanted characters */
var valueOnlyReg = new RegExp(m.Filter,"gi");
return m.Field.DataValue.replace(valueOnlyReg,"");
}
}

function OnCrmPageLoad()
{
var phoneMask = new Mask("(##)###-####");
phoneMask.Field = crmForm.all.telephone1;
phoneMask.Filter = "\\D"; //Unmask Filter - Strip Everything which is not a Number
phoneMask.Mask();

var cellMask = new Mask("+(##) ### ####");
cellMask.Field = crmForm.all.telephone2;
phoneMask.OnLoad = true;
cellMask.Filter = "\\D"; //Unmask Filter - Strip Everything which is not a Number
cellMask.Mask();
}

OnCrmPageLoad();

23 comments:

Unknown said...

Welcome back, Adi!
I missed your posts a lot!

Anonymous said...

Thanks for the post! it will be very useful to me xD

Taylor said...

I have an attribute which show as a ‘bit’ field in a CRM 4.0 database. I need to dynamically add it to a dynamic entity then set its value to either 0 or 1. Which is the best way of doing this?

Anonymous said...

This is a good article & good site.Thank you for sharing this article. It is help us following categorize:
digital supply chain management, Delivering high-quality service for your business applications,
Solutions for all Industries,
Getting your applications talking is the key to better business processes,
Rapid web services solutions for real business problems,
Understanding Your Data is the Key to Good Decision-Making,
Web-based Corporate Document Management System,
Outsourcing Solution,
Financial and Operations Business Intelligence Solution,

prologic-corp

ERP said...

ERPTREE is a leading oracle fuison HCM Training Institute. we offer this course through online we have great
experience in succeeding students through online courses. we can calculate our performance through their honest
comments in our sites in supporting our services. we have referral program so candidates can earn money through
referral. you can share your live experience with other can generate you some money.


Oracle Fusion HCM Online Training

Oracle Fusion SCM Training in Hyderabad said...

very good and interesting post,your website gives us best information. This is just the kind of information that i had been looking for.
oracle fusion Scm training in Hyderabad

Unknown said...

nice

George said...

Your website is one of the best website for information i need. Love your website man. Keep adding more articles.

digital tucr said...

ExcelR Offers Business Analytics / Data Scientist Course / Data Analytics Training & Data Science Course Training In Bangalore, With 100% Placement.

Tripu Design said...

This is an amazing blog, thank you so much for sharing such valuable information with us.
Visit for best logo and brochure designing services at- brochure designer in delhi.
graphic designer in delhi
freelance graphic designer in delhi
freelance graphic designer in delhi ncr
freelance graphic designer in noida
freelance logo designer in delhi
freelance logo designer in delhi ncr
freelance web designer in delhi ncr
freelance website designer in delhi ncr
freelance designer in delhi
freelance website designer in delhi
freelance web designer in delhi
freelance graphic designer services in delhi
freelancer graphic designer services in delhi ncr
freelancer graphic designer services in delhi
freelancer graphic services in delhi ncr
freelancer logo services in delhi
freelancer logo services in delhi ncr
freelancer web designer services in delhi ncr
freelancer web designer services in delhi
freelance web designer services in delhi
freelance website designer services in delhi
freelance website designer services in delhi ncr
freelance logo designer service in delhi
freelance logo designer service in delhi ncr
logo designer in delhi
brochure design in delhi
logo design in delhi
freelance logo design in delhi
freelance logo designer in gurgaon
freelance logo designer in noida

Repairtech Solutions said...

Aw, this was a very good post. Finding the time and actual effort to create a superb article… but what can I say… I put things off a whole lot and never seem to get anything done. onsite mobile repair bangalore I’m impressed, I have to admit. Seldom do I encounter a blog that’s both educative and entertaining, and let me tell you, you have hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. I am very happy that I came across this during my search for something concerning this. asus display repair bangalore Oh my goodness! Incredible article dude! Thank you so much, However I am having issues with your RSS. I don’t understand the reason why I am unable to join it. Is there anyone else getting the same RSS issues? Anybody who knows the answer will you kindly respond? Thanx!! huawei display repair bangalore

Repairtech Solutions said...

An outstanding share! I have just forwarded this onto a co-worker who has been conducting a little research on this. And he in fact ordered me breakfast simply because I stumbled upon it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanx for spending some time to talk about this issue here on your website. online laptop repair center bangalore After going over a number of the blog articles on your website, I seriously like your way of blogging. I added it to my bookmark webpage list and will be checking back in the near future. Please check out my website as well and let me know what you think. dell repair center bangalore

Repairtech Solutions said...


This excellent website definitely has all of the information I needed about this subject and didn’t know who to ask. macbook repair center bangalore There's definately a great deal to know about this issue. I love all the points you made. acer repair center bangalore

sara jenifer said...

I think you did an awesome job explaining it. Sure beats having to research it on my own. Thanks
Rajasthan University BCOM 1st, 2nd & Final Year Time Table 2020

Unknown said...

If you're trying to lose weight then you absolutely need to jump on this totally brand new personalized keto meal plan diet.

To create this keto diet service, licenced nutritionists, personal trainers, and cooks have joined together to develop keto meal plans that are powerful, convenient, price-efficient, and delicious.

From their first launch in January 2019, hundreds of people have already transformed their figure and well-being with the benefits a great keto meal plan diet can provide.

Speaking of benefits; in this link, you'll discover eight scientifically-confirmed ones offered by the keto meal plan diet.

Online Front said...

Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.
If you want Digital Marketing Serives :-
Digital marketing Service in Delhi
SMM Services
PPC Services in Delhi
Website Design & Development Packages
SEO Services PackagesLocal SEO services
E-mail marketing services
YouTube plans

Excelr Tuhin said...

I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
data science certification

Unknown said...

I missed your posts a lot! Fut hair transplant cost

Priya Rathod said...

Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post.
AWS Training in Hyderabad
AWS Course in Hyderabad

Unknown said...

Comprehensive experience of association with 100+ corporates globally. Highly exclusive and bespoke training problems starting from the entry-level and varying to leadership levels. We are providing corporate digital marketing training in Hyderabad for the last many years and have created a significant presence as a corporate digital marketing training company.

Our Way of Corporate Training

Over the last few years, the evolution of the internet and its applications has reported an immense adaption amongst the people. The digital transformation has just created an upside change in the way the businesses used to operate earlier. It has fundamentally shifted the focus of companies towards new and improved ways of operating the business. In this new era of digitization, any business that denies going with this trend may get disrupted within the next few years. The corporate digital marketing training in Hyderabad has helped many companies and business ventures to upscale their business and help them achieve exponential growth. Our training model is strategically designed and developed to inhibit businesses get the most profound and right amount of knowledge that helps them to upscale their business. We intend to provide any business the source of training that helps them to make a profitable source of revenue with the help of our training.

So let’s get a brief insight into our role and the strategies that we focus upon to upscale any business. We work on a 5 step methodology that is quite simple but extremely effective in creating a digital presence for the company.
Website URL: https://www.emblixsolutions.com/corporate-digital-marketing-training-in-hyderabad/

PDUSU BA 2nd Year Exam Result said...

Thanks for sharing the useful information.

PDUSU BA 1st Year Exam Result | PDUSU BA 3rd Year Exam Result

Heaven Designs said...

We make sure that our partners are able to delight their customers and deliver as per the commitments. This residential solar installation achieved by fast turnaround time, least revisions, a database of AJH & utility requirements for most accurate permit plan set creation and vast network of PE stamp partners. We have in-depth knowledge of handling Residential Permit Planset, commercial, shops/ independent buildings & carports. Heaven is your go-to solar design partner for sales proposals and PV permit designs !

Heaven Designs said...

We at Mytanfarma help you to realize three ultimate goals :
PROFIT to customer - Managed farmland in Bangalore offers the potential for higher rates of return due to the scope for appreciation in the value of land, tax-free agricultural income, and value enhancement of the land through forestry and plantation crops. Horticultural crops can provide seasonal income, while timber can fetch handsome returns as a long-term benefit.