Considerations:
- The full code for this modification is available at the bottom of this post for those who don't want to follow step by step. I wouldn't either, the steps are really just to learn the process I took to make this modification so you might try to make your own.
- This post assumes you have a minimum level of programming experience. I try to be as plain as I can be but if you have never touched an editor before maybe you should ask around and find someone to do this for you. It is insanely easy to completely botch things up.
- This post DOES NOT cover adding this modification to Studio. Any field you modify with this code wil work 100% in studio but you will not be able to add a new field with this modifiction already in place. You will have to add a checkbox and then modify the PHP manually. I will get to making a post on how to make a fully realized custom field definition that is avaialble in Studio but not this time.
Loading the jQuery-mask plugin
- Download the plugin from here, unzip it and look int the 'dist' folder. There you will find jquery.mask.js. Copy this file to /custom/Javascript/jQuery-Mask.
- Create the file custom/Extension/application/Ext/JSGroupings/jQuery-mask_grouping.php. This will hold our addition to the JSGroupings. Look here if you need information on what JSGroupings is. This is what the contents of this file should be.
Create the SugarCRM Custom Field Definition
Once that is done, we have to create the custom SugarRM field definition. That part is even easier.- Find the directory clients/base/fields/phone.
- Copy that entire directory to custom/clients/base/fields/masked-phone. Make sure 'masked-phone' is lower case.
- In that directory rename phone.js to masked-phone.js (again remember it has to be lower case)
- Now edit masked-phone.js and add this code that will change the phone number field to a masked verison. Add this function right below the initialize() function. It will enable each phone field as it is rendered and define the phone number mask. As you can see I added code so that if there are fewer than 8 numbers it uses one mask and if there are more than 8 numbers it changes the mask to include area code.
- Now we need to update how the phone numbers in this field definition are rendered. Edit the file custom/clients/base/fields/masked-phone/edit.hbs and add the code class "phone_us" to the <input> element. To do that you must look for the code that looks like this class="inherit-width" and change it to this class="inherit-width phone_us"
- Then edit custom/clients/base/fields/switchery/detail.hbs and do the same thing as above
Updating SugarCRM with the new fields
That is all there is to that. Now we have a custom field definition called masked-phone that we can use to convert any phone field we want. Now we need to tell SugarCRM which phone fields we want to modify. In my setup I changed two phone fields in Accounts by editing the file custom/modules/Accounts/clients/base/views/record/record.php. I simply added a 'type' element to the array for the fields I wanted to change like thisYou will also have to update the create.php if you have one. Once that is done, all you have to do is run a
- Quick Repair and Rebuild
- Rebuild JS Groupings
- Another Quick Repair and Rebiold
- Start using the fields.
As Promised
Here is a link to all the files
No comments:
Post a Comment