Custom Actions on Binding Error Link Clicks

When errors messages for fields are displayed and the fields have associated field IDs on the page the fields are highlighted when clicked. In addition there's also a JavaScript event that is fired that can be used to trap these clicks and perform additional actions.

The JavaScript client event is called:

onBindingErrorLink

An example of an operation that requires this sort of event handling is when errors are displayed on a Tab page and the page where the error control clicked is not visible. By hooking the onBindingErrorLink event you can trap the link click and walk up to the tabpage and make it visible. Assuming a tab control named Tabs and and each tab's CSS class being set to a .tabpage class you can do the following:

function onBindingErrorLink(control) {
    var jTabPage = $(control).parents(".tabpage:first");
    if (jTabPage.length > 0)
        ActivateTab("Pages", jTabPage.get(0).id);
}

The function is passed the DOM element that contains the error. This code takes the control turns it into a jQuery object and searches backwards for the tabpage element by looking for the .tabpage class. If found the element is activated.

Note the Tab control doesn't use jQuery natively to use this particular approach you'd have to add jQuery to your page. Without jQuery the code looks like this:

function onBindingErrorLink(control) {

        //  Find the parent 'tab' page id by walking up the DOM tree
        while (control.parentNode) {
            control = control.parentNode;
            if (!control)
                break;

            if (control.className == "tabpage") {
                ActivateTab("Pages", control.id);
                return;
            }
    }
}

© West Wind Technologies, 1996-2016 • Updated: 11/26/09
Comment or report problem with topic