rice-framework/krad-web/src/main/webapp/krad/scripts/krad.validate.js
/**
 * Writes the any messages in the client or server side message arrays at the field level, applies the correct style
 * classes, and displays icons as necessary.  These messages are hidden content unless tooltips for messages are
 * turned off.
 * @param id id of the field to write messages to
 */
Writes the any messages in the client or server side message arrays at the field level, applies the correct style
classes, and displays icons as necessary.  These messages are hidden content unless tooltips for messages are
turned off.
@param id id of the field to write messages to
Writes the any messages in the client or server side message arrays at the field level applies the correct style classes and displays icons as necessary . These messages are hidden content unless tooltips for messages are turned off . @param id id of the field to write messages to
function writeMessagesAtField(id) {
    var field = jQuery("#" + id);
    var data = getValidationData(field);
    if (data && data.displayMessages) {
        if (!data.errors) {
            data.errors = [];
        }
        if (!data.warnings) {
            data.warnings = [];
        }
        if (!data.info) {
            data.info = [];
        }
        var messagesDiv = jQuery("[data-messages_for='" + id + "']");
        var createMessagesDiv = messagesDiv.length === 0;
        if (createMessagesDiv) {
            messagesDiv = jQuery("<div id='" + id +
                    "_errors' class='alert' data-messages_for='" + id + "' style='display: none;'>");
        }
        if (data.useTooltip) {
            messagesDiv.hide();
        }
        else {
            messagesDiv.show();
        }
        messagesDiv.empty();
        var clientMessages = jQuery("<div class='" + kradVariables.CLIENT_MESSAGE_ITEMS_CLASS + "'><ul>"
                + generateListItems(data.errors, kradVariables.ERROR_MESSAGE_ITEM_CLASS, 0, false, errorImage)
                + generateListItems(data.warnings, kradVariables.WARNING_MESSAGE_ITEM_CLASS, 0, false, warningImage)
                + generateListItems(data.info, kradVariables.INFO_MESSAGE_ITEM_CLASS, 0, false, infoImage) + "</ul></div>");
        var editLink = "";
        if (field.data(kradVariables.INLINE_EDIT.INLINE_EDIT_DATA_ATTR)) {
            var editText = getMessage(kradVariables.MESSAGE_EDIT);
            editLink = " <a onclick=\"activateInlineEdit('" + id + "'); return false;\">" + editText + "</a>";
        }
        var serverMessages = jQuery("<div class='" + kradVariables.SERVER_MESSAGE_ITEMS_CLASS + "'><ul>"
                + generateListItems(data.serverErrors, kradVariables.ERROR_MESSAGE_ITEM_CLASS, 0, false, errorImage, editLink)
                + generateListItems(data.serverWarnings, kradVariables.WARNING_MESSAGE_ITEM_CLASS, 0, false, warningImage, editLink)
                + generateListItems(data.serverInfo, kradVariables.INFO_MESSAGE_ITEM_CLASS, 0, false, infoImage, editLink) + "</ul></div>");
        var hasServerMessages = false;
        if (jQuery(clientMessages).find("ul").children().length) {
            if (createMessagesDiv) {
                field.append(messagesDiv);
                createMessagesDiv = false;
            }
            jQuery(clientMessages).appendTo(messagesDiv);
        }
        if (jQuery(serverMessages).find("ul").children().length) {
            if (createMessagesDiv) {
                field.append(messagesDiv);
                createMessagesDiv = false;
            }
            jQuery(serverMessages).appendTo(messagesDiv);
            hasServerMessages = true;
        }
        var showImage = data.showIcons;
        if (field.parents(".uif-tableCollectionLayout").length) {
            showImage = false;
        }
        jQuery("#" + id + " > .uif-validationImage").remove();
        field.removeClass(kradVariables.HAS_ERROR_CLASS);
        field.removeClass(kradVariables.HAS_MODIFIED_ERROR_CLASS);
        field.removeClass(kradVariables.HAS_WARNING_CLASS);
        field.removeClass(kradVariables.HAS_INFO_CLASS);
        if (jQuery(messagesDiv).find(".uif-errorMessageItem-field").length) {
            if (data.errors.length) {
                jQuery(messagesDiv).find(".uif-clientMessageItems").addClass(kradVariables.CLIENT_ERROR_DIV_CLASS);
            }
            if (data.serverErrors.length) {
                jQuery(messagesDiv).find(".uif-serverMessageItems").addClass(kradVariables.CLIENT_ERROR_DIV_CLASS);
            }
            if (data.fieldModified && data.errors.length == 0) {
                field.addClass(kradVariables.HAS_MODIFIED_ERROR_CLASS);
                if (showImage) {
                    jQuery(messagesDiv).before(errorGreyImage);
                }
            }
            else {
                field.addClass(kradVariables.HAS_ERROR_CLASS);
                if (showImage) {
                    jQuery(messagesDiv).before(errorImage);
                }
            }
            if (hasServerMessages) {
                data.tooltipTheme = "uif-tooltip-error-ss";
            }
            else {
                data.tooltipTheme = "uif-tooltip-error-cs";
            }
            handleTabStyle(id, true, false, false);
        }
        else if (jQuery(messagesDiv).find(".uif-warningMessageItem-field").length) {
            if (data.warnings.length) {
                jQuery(messagesDiv).find(".uif-clientMessageItems").addClass(kradVariables.CLIENT_WARNING_DIV_CLASS);
            }
            if (data.serverWarnings.length) {
                jQuery(messagesDiv).find(".uif-serverMessageItems").addClass(kradVariables.CLIENT_WARNING_DIV_CLASS);
            }
            field.addClass(kradVariables.HAS_WARNING_CLASS);
            if (showImage) {
                jQuery(messagesDiv).before(warningImage);
            }
            if (hasServerMessages) {
                data.tooltipTheme = "uif-tooltip-warning-ss";
            }
            else {
                data.tooltipTheme = "uif-tooltip-warning-cs";
            }
            handleTabStyle(id, false, true, false);
        }
        else if (jQuery(messagesDiv).find(".uif-infoMessageItem-field").length) {
            if (data.info.length) {
                jQuery(messagesDiv).find(".uif-clientMessageItems").addClass(kradVariables.CLIENT_INFO_DIV_CLASS);
            }
            if (data.serverInfo.length) {
                jQuery(messagesDiv).find(".uif-serverMessageItems").addClass(kradVariables.CLIENT_INFO_DIV_CLASS);
            }
            field.addClass(kradVariables.HAS_INFO_CLASS);
            if (showImage) {
                jQuery(messagesDiv).before(infoImage);
            }
            if (hasServerMessages) {
                data.tooltipTheme = "uif-tooltip-info-ss";
            }
            else {
                data.tooltipTheme = "uif-tooltip-info-cs";
            }
            handleTabStyle(id, false, false, true);
        }
        else {
            messagesDiv.hide();
            handleTabStyle(id, false, false, false);
        }
    }
}
function writeMessagesAtField ( id ) { var field = jQuery ( "#" + id ) ; var data = getValidationData ( field ) ; if ( data && data . displayMessages ) { if ( ! data . errors ) { data . errors = [ ] ; } if ( ! data . warnings ) { data . warnings = [ ] ; } if ( ! data . info ) { data . info = [ ] ; } var messagesDiv = jQuery ( "[data-messages_for='" + id + "']" ) ; var createMessagesDiv = messagesDiv . length === 0 ; if ( createMessagesDiv ) { messagesDiv = jQuery ( "<div id='" + id + "_errors' class='alert' data-messages_for='" + id + "' style='display: none;'>" ) ; } if ( data . useTooltip ) { messagesDiv . hide ( ) ; } else { messagesDiv . show ( ) ; } messagesDiv . empty ( ) ; var clientMessages = jQuery ( "<div class='" + kradVariables . CLIENT_MESSAGE_ITEMS_CLASS + "'><ul>" + generateListItems ( data . errors , kradVariables . ERROR_MESSAGE_ITEM_CLASS , 0 , false , errorImage ) + generateListItems ( data . warnings , kradVariables . WARNING_MESSAGE_ITEM_CLASS , 0 , false , warningImage ) + generateListItems ( data . info , kradVariables . INFO_MESSAGE_ITEM_CLASS , 0 , false , infoImage ) + "</ul></div>" ) ; var editLink = "" ; if ( field . data ( kradVariables . INLINE_EDIT . INLINE_EDIT_DATA_ATTR ) ) { var editText = getMessage ( kradVariables . MESSAGE_EDIT ) ; editLink = " <a onclick=\"activateInlineEdit('" + id + "'); return false;\">" + editText + "</a>" ; } var serverMessages = jQuery ( "<div class='" + kradVariables . SERVER_MESSAGE_ITEMS_CLASS + "'><ul>" + generateListItems ( data . serverErrors , kradVariables . ERROR_MESSAGE_ITEM_CLASS , 0 , false , errorImage , editLink ) + generateListItems ( data . serverWarnings , kradVariables . WARNING_MESSAGE_ITEM_CLASS , 0 , false , warningImage , editLink ) + generateListItems ( data . serverInfo , kradVariables . INFO_MESSAGE_ITEM_CLASS , 0 , false , infoImage , editLink ) + "</ul></div>" ) ; var hasServerMessages = false ; if ( jQuery ( clientMessages ) . find ( "ul" ) . children ( ) . length ) { if ( createMessagesDiv ) { field . append ( messagesDiv ) ; createMessagesDiv = false ; } jQuery ( clientMessages ) . appendTo ( messagesDiv ) ; } if ( jQuery ( serverMessages ) . find ( "ul" ) . children ( ) . length ) { if ( createMessagesDiv ) { field . append ( messagesDiv ) ; createMessagesDiv = false ; } jQuery ( serverMessages ) . appendTo ( messagesDiv ) ; hasServerMessages = true ; } var showImage = data . showIcons ; if ( field . parents ( ".uif-tableCollectionLayout" ) . length ) { showImage = false ; } jQuery ( "#" + id + " > .uif-validationImage" ) . remove ( ) ; field . removeClass ( kradVariables . HAS_ERROR_CLASS ) ; field . removeClass ( kradVariables . HAS_MODIFIED_ERROR_CLASS ) ; field . removeClass ( kradVariables . HAS_WARNING_CLASS ) ; field . removeClass ( kradVariables . HAS_INFO_CLASS ) ; if ( jQuery ( messagesDiv ) . find ( ".uif-errorMessageItem-field" ) . length ) { if ( data . errors . length ) { jQuery ( messagesDiv ) . find ( ".uif-clientMessageItems" ) . addClass ( kradVariables . CLIENT_ERROR_DIV_CLASS ) ; } if ( data . serverErrors . length ) { jQuery ( messagesDiv ) . find ( ".uif-serverMessageItems" ) . addClass ( kradVariables . CLIENT_ERROR_DIV_CLASS ) ; } if ( data . fieldModified && data . errors . length == 0 ) { field . addClass ( kradVariables . HAS_MODIFIED_ERROR_CLASS ) ; if ( showImage ) { jQuery ( messagesDiv ) . before ( errorGreyImage ) ; } } else { field . addClass ( kradVariables . HAS_ERROR_CLASS ) ; if ( showImage ) { jQuery ( messagesDiv ) . before ( errorImage ) ; } } if ( hasServerMessages ) { data . tooltipTheme = "uif-tooltip-error-ss" ; } else { data . tooltipTheme = "uif-tooltip-error-cs" ; } handleTabStyle ( id , true , false , false ) ; } else if ( jQuery ( messagesDiv ) . find ( ".uif-warningMessageItem-field" ) . length ) { if ( data . warnings . length ) { jQuery ( messagesDiv ) . find ( ".uif-clientMessageItems" ) . addClass ( kradVariables . CLIENT_WARNING_DIV_CLASS ) ; } if ( data . serverWarnings . length ) { jQuery ( messagesDiv ) . find ( ".uif-serverMessageItems" ) . addClass ( kradVariables . CLIENT_WARNING_DIV_CLASS ) ; } field . addClass ( kradVariables . HAS_WARNING_CLASS ) ; if ( showImage ) { jQuery ( messagesDiv ) . before ( warningImage ) ; } if ( hasServerMessages ) { data . tooltipTheme = "uif-tooltip-warning-ss" ; } else { data . tooltipTheme = "uif-tooltip-warning-cs" ; } handleTabStyle ( id , false , true , false ) ; } else if ( jQuery ( messagesDiv ) . find ( ".uif-infoMessageItem-field" ) . length ) { if ( data . info . length ) { jQuery ( messagesDiv ) . find ( ".uif-clientMessageItems" ) . addClass ( kradVariables . CLIENT_INFO_DIV_CLASS ) ; } if ( data . serverInfo . length ) { jQuery ( messagesDiv ) . find ( ".uif-serverMessageItems" ) . addClass ( kradVariables . CLIENT_INFO_DIV_CLASS ) ; } field . addClass ( kradVariables . HAS_INFO_CLASS ) ; if ( showImage ) { jQuery ( messagesDiv ) . before ( infoImage ) ; } if ( hasServerMessages ) { data . tooltipTheme = "uif-tooltip-info-ss" ; } else { data . tooltipTheme = "uif-tooltip-info-cs" ; } handleTabStyle ( id , false , false , true ) ; } else { messagesDiv . hide ( ) ; handleTabStyle ( id , false , false , false ) ; } } }
Writes the any messages in the client or server side message arrays at the field level, applies the correct style
 classes, and displays icons as necessary.
Writes the any messages in the client or server side message arrays at the field level applies the correct style classes and displays icons as necessary .
//initialize data if not present
 //ensure the messagesDiv is hidden and empty
 //generate client side based messages
 // Create an edit link for inline edit fields which now have associated server messages
 //generate server side based messages
 //only append if messages exist
 //do not show the message icon next to field if this field is in a table collection layout
 //remove any image and previous styles that may already be present
 //show appropriate icons/styles based on message severity level
 //This is to represent the field has been changed after a server error, but may or
 //may not be fixed - greyed out image/border
