ExtJS 4 - Printing Panels does not render Checkboxes and Radio Buttons?

248 views Asked by At

I am building an ExtJS4 Web Application. I have a form that the user can fill up. I am able to do basic CRUD on the data that the user inputs. I added functionality to this by enabling the user to print the form. To achieve this, I wrote an override for the form.Panel X-Types as such. I modified a code I found online:

print: function(pnl) {

    if (!pnl) {
        pnl = this;
    }

    // instantiate hidden iframe

    var iFrameId = "printerFrame";
    var printFrame = Ext.get(iFrameId);

    if (printFrame === null) {
        printFrame = Ext.getBody().appendChild({
            id: iFrameId,
            tag: 'iframe',
            cls: 'x-hidden',
            style: {
                display: "none"
            }
        });
    }

    var cw = printFrame.dom.contentWindow;
    var stylesheets = "";
    var markup;
    // instantiate application stylesheets in the hidden iframe



    var printTask = new Ext.util.DelayedTask(function(){
        // print the iframe
        cw.print();

        // destroy the iframe
        Ext.fly(iFrameId).destroy();

    });


    var strTask = new Ext.util.DelayedTask(function(){
        var str = Ext.String.format('<html><head>{0}</head><body>{1}</body></html>',stylesheets,markup);


        // output to the iframe
        cw.document.open();
        cw.document.write(str);
        cw.document.close();

        // remove style attrib that has hardcoded height property
        //             cw.document.getElementsByTagName('DIV')[0].removeAttribute('style');
        printTask.delay(500);

    });

    var markUpTask = new Ext.util.DelayedTask(function(){
        // get the contents of the panel and remove hardcoded overflow properties
        markup = pnl.getEl().dom.innerHTML;
        while (markup.indexOf('overflow: auto;') >= 0) {
            markup = markup.replace('overflow: auto;', '');
        }
        while (markup.indexOf('background: rgb(255, 192, 203) !important;') >= 0) {
            markup = markup.replace('background: rgb(255, 192, 203) !important;', 'background: pink !important;');
        }

        strTask.delay(500);
    });


    var styleSheetConcatTask = new Ext.util.DelayedTask(function(){

        // various style overrides
        stylesheets += ''.concat(
            "<style>", 
            ".x-panel-body {overflow: visible !important;}",
            // experimental - page break after embedded panels
            // .x-panel {page-break-after: always; margin-top: 10px}",
            "</style>"
        );

        markUpTask.delay(500);
    });


    var styleSheetCreateTask = new Ext.util.DelayedTask(function(){


        for (var i = 0; i < document.styleSheets.length; i++) {
            stylesheets += Ext.String.format('<link rel="stylesheet" href="{0}" />', document.styleSheets[i].href);
        }
        styleSheetConcatTask.delay(500);
    });

    styleSheetCreateTask.delay(500);
}

I used the delay functions to ensure that the function finishes its operations because there are times that the print preview fails.

This code works, it can print out text fields, labels, as well as field sets. However, it does not render radio buttons at all. Now, I am not sure why it does not.

0

There are 0 answers