Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jQuery UI's Highlight and Error widgets?

Tags:

jquery-ui

jQuery UI has some nice convenient CSS styles for alerting and highlighting. I can see it at the themeroller site -- look on the right hand side. Is there a Javascript interface to these styles? Do we use hard-coded CSS? Where is this documented?

Is there method list, a cheatsheat, or anything other than the interactive docs on jQuery UI?

like image 945
NO WAR WITH RUSSIA Avatar asked Jul 02 '10 19:07

NO WAR WITH RUSSIA


People also ask

How is the default formatting for a jQuery UI widget done?

To change the defaults, you can use the event, collapsible, heightStyle, and animated options. The basic formatting of the accordion is done by the CSS for jQuery UI, but you can use CSS to format the contents within the panels.

How does jQuery UI work?

jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice.


2 Answers

Apply the appropriate CSS classes for the desired interaction cue from the UI/Theming/API page: .ui-state-highlight for highlight and .ui-state-error for error. You can do it statically or use .addClass('ui-state-highlight') or .addClass('ui-state-error') to do it dynamically.

like image 113
flipdoubt Avatar answered Sep 29 '22 16:09

flipdoubt


I have adapted a short jQuery function to convert a given set of divs (containing text) into error/highlight elements.

You can see it in action on this jsFiddle.

Here is the javascript:

//function to create error and alert dialogs
function errorHighlight(e, type, icon) {
    if (!icon) {
        if (type === 'highlight') {
            icon = 'ui-icon-info';
        } else {
            icon = 'ui-icon-alert';
        }
    }
    return e.each(function() {
        $(this).addClass('ui-widget');
        var alertHtml = '<div class="ui-state-' + type + ' ui-corner-all" style="padding:0 .7em;">';
        alertHtml += '<p>';
        alertHtml += '<span class="ui-icon ' + icon + '" style="float:left;margin-right: .3em;"></span>';
        alertHtml += $(this).text();
        alertHtml += '</p>';
        alertHtml += '</div>';

        $(this).html(alertHtml);
    });
}

//error dialog
(function($) {
    $.fn.error = function() {
        errorHighlight(this, 'error');
    };
})(jQuery);

//highlight (alert) dialog
(function($) {
    $.fn.highlight = function() {
        errorHighlight(this, 'highlight');
    };
})(jQuery);
like image 39
jofitz Avatar answered Sep 29 '22 14:09

jofitz