JQuery Dialog People Picker Validation

So this is a bit of a rugged solution but its just nice to have SOME validation on a people picker within a JQuery dialog before that sucker disappears (when a user clicks OK). Below is an example dialog declaration and the click event over-ride function to validate the people picker (Check Names link). Unfortunately it does require the ‘Are you sure’ pop up, just so we can give the people picker elements enough time to change based on the built in ‘check names validation’. If we don’t have this pause then the validation is done before the Click event has completed and updated the relevant elements. I’m sure you could use some wait function instead if you like. As you can see, the people picker control gets broken down in to quite the html nightmare- you should view the source of a page with one just for kicks.

$(‘a[id*=fromUser_checkNames]’).click(
    function() {
    alert(“Are you sure you want to delegate this responsibility?”);
    if($(‘span[id*=toUser_errorLabel]’) != null){
        if($(‘span[id*=toUser_errorLabel]’)[0].innerHTML != “”){
                   alert(“Invalid User”);}
                }
    }
 
    );
 
$(‘#delegation’).dialog({
            bgiframe: true,
                autoOpen: false,
                width: 600,
                modal: true,
                buttons: {
                        “Cancel”: function() {
                                $(this).dialog(“close”);
                                $(‘input[id*=enddate]’).val(“”);
                                $(‘input[id*=startdate]’).val(“”);
                $(‘div[id*=toUser_upLevelDiv]’).text(“”);
                showDelegation = false;
 
                        } ,
                        “Ok”: function() {
                             $(‘a[id*=toUser_checkNames]’).click();
                             $(‘a[id*=fromUser_checkNames]’).click();
                             if($(‘span[id*=toUser_errorLabel]’) != null){
                                if($(‘span[id*=toUser_errorLabel]’)[0].innerHTML != “”){
                                    return false;
                                }
                              }
                                $(this).dialog(“destroy”).appendTo(“#aspnetForm”);
                 eval($(“#<%= hdnDelegatePostback.ClientID %>”).val());
 
                        }
            }
        });
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