Luciuz
Luciuz

Reputation: 1767

Custom data-role in jquery mobile

Is there a way to create custom handler for loaded data via jquery mobile core. For example, if after my form submition jquery mobile get this:

<div data-role="message">
    <message>Error</message>    
    <selector>#password, #login</selector>
</div>

Jquery mobile will not have to render blank page into content, but just execute something like this:

//grab
var message = $(response).find('message').text();
var selector = $(response).find('selector').text();

//show and highlight
$.mobile.showPageLoadingMsg($.mobile.pageLoadErrorMessageTheme, message, true);
setTimeout($.mobile.hidePageLoadingMsg, 1500);
if (selector) $(selector).addClass('error');

Upvotes: 0

Views: 442

Answers (1)

Luciuz
Luciuz

Reputation: 1767

Here it is my creepy solution

(function($){
    $(document).on('pageload', function(event, data) {

        var $this = $(data.xhr.responseText);

        if ($this.attr('data-role')=='message') {
            //grab
            var message = $this.find('message').text();
            var selector = $this.find('selector').text();

            //show and highlight
            $.mobile.showPageLoadingMsg($.mobile.pageLoadErrorMessageTheme, message, true);
            setTimeout($.mobile.hidePageLoadingMsg, 1500);
            if (selector) $(selector).addClass('error');

            //stop defaults
            data.deferred.reject(data.absUrl, data.options);
        }
  });
})(jQuery);

Upvotes: 1

Related Questions