FIM 2010 Portal: Dynamic RCDC with Jquery – Enforcing displayname controls

This is follow up on the intro to RCDC and Jquery found here. Lets look at an a basic example of how to use Jquery to add some dynamic controls to our RCDC form,

Requirements

1- Remove tailing and leading spaces in the firstname, lastname, displayname fields. Take care of some fat finger space being entered.

2- Take only the first letter from the middlename

3- Remove any caps and change the casing to proper casing, first letter upper and the rest lowercase. How many times do we see people copy and paste from an email “Create an new account for JOHN DOE” and then you have an inconsistent looking directory.

4- Set the Displayname to “FN MI LN”. Make the displayname field read only.

Here is the code

<asp:Content id=”content1″ ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<script src=”/_layouts/images/MSILM2/Scripts/jquery-1.7.2.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>

$(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
DisableDisplayName();
SetDisplayName();
});

$(function () {
DisableDisplayName();
SetDisplayName();
});

function DisableDisplayName() {
$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_DisplayName_control_internalTextBox”).attr(“readonly”, “true”);
}

function SetDisplayName() {
$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_FirstName_control_internalTextBox, #ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_LastName_control_internalTextBox, #ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_MiddleName_control_internalTextBox”).change(function () {
var typeOfUserAccount = $(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_TypeOfUserAccount_control_internalDropDownList”).val();
var firstName = $.trim($(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_FirstName_control_internalTextBox”).val());
//remove caps and set it to proper casing
firstName = firstName.toLowerCase().replace(/\b[a-z]/g, function (letter) {
return letter.toUpperCase();
});
var lastName = $.trim($(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_LastName_control_internalTextBox”).val());

//remove caps and set it to proper casing
lastName = lastName.toLowerCase().replace(/\b[a-z]/g, function (letter) {
return letter.toUpperCase();
});
var middleName = $.trim($(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_MiddleName_control_internalTextBox”).val());
//middlename should always be Uppercase
middleName = middleName.toUpperCase();
var displayName;
if ((lastName != “”) && (firstName != “”) && (middleName != “”)) displayName = firstName + ” ” + middleName.substring(0, 1) + ” ” + lastName;
else if ((lastName != “”) && (firstName != “”)) displayName = firstName + ” ” + lastName;
else if (lastName != “”) displayName = lastName;
else if (firstName != “”) displayName = firstName;
else if ((lastName == “”) && (firstName == “”) && (middleName == “”)) displayName = “”;

}

$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_FirstName_control_internalTextBox”).val(firstName);
$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_LastName_control_internalTextBox”).val(lastName);
$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_MiddleName_control_internalTextBox”).val(middleName.substring(0, 1));
$(“#ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_DisplayName_control_internalTextBox”).val(displayName);
});
}

</script>
<IdentityManagement:CreatePerson runat=”server” id=”CreatePerson”/>
</asp:Content>

PageRequestmanager will load the functions each time the page is refreshed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s