...
Start by logging in as an administrator, and navigate to the Setup tabpage. Under the Configuration category, click on the Custom Code then add new and set the name to “Verify User Account Name”. In the “Code” field, copy and paste the following:
Code Block | ||
---|---|---|
| ||
//Reference: Castle.MonoRail.Framework //Reference: System.Data //Reference: Presentation using System; using Castle.MonoRail.Framework; using Logisense.Boss.Logic.DomainModel; namespace Logisense.Boss.CustomScripts{ public class AJAXCheckAccountNameIfExists : IDynamicAction { public void Execute(Controller controller) { string accountName = controller.Request["accountName"]; bool exists = false; if(!string.IsNullOrEmpty(accountName)) { try { if(User.GetByName(accountName)!=null) { exists = true; } } catch (Exception) {} } controller.RenderText(exists ? "true" : "false"); } } } |
...
Next, we need to configure the page extension. Create a new page extension called “Check Account Name” targetting targeting the page “User/Add”. Paste the following code into the script box:
Code Block | ||
---|---|---|
| ||
jQuery("#User.Name").change(function() { var elemID = this.id; var elemValue = this.value; jQuery.get("/AJAXCheckAccountNameIfExists.rails", { accountName: this.value }, function(data) { if (data === 'true') { //make it invalid SetInvalidField(elemID); alert('Account Name ' + elemValue + ' already exists'); } else { SetValidField(elemID); } }); }); |
...