3.2.0

Tips for CheckBox Template

To show 'Yes' and 'No' after checkbox :-)

obj.setContent("box/text", function() {return this.getControlProperty("value") ? 'Yes' : 'No'});


My checkbox template when my data is not Boolean but 'Y' & 'N' :-)

// my checkbox 
My.CheckBox = AW.Templates.ImageText.subclass();
My.CheckBox.create = function () {
    var obj = this.prototype;
    obj.setClass("value", function () {
        return this.getControlProperty("value") == 'Y';
    });
    obj.setClass("toggle", "checkbox");
    obj.setClass("templates", "checkbox");
    obj.setAttribute("awx", "toggle");
    var marker = new AW.HTML.SPAN;
    marker.setClass("item", "marker");
    obj.setContent("box/marker", marker);
    obj.setContent("box/text", function() {return (this.getControlProperty("value") == 'Y') ? 'Yes' : 'No'});
    obj.setEvent("onclick", function () {
        var value = this.getControlProperty("value");
        this.setControlProperty("value", (value == 'Y') ? 'N' : 'Y');
    });
    obj.startEdit = null;
};


It is hardcoded to Y/N for now, but shall develop more generic class to have APIs like following.

// chk.defineCheckedProperty("true", "Y");
// chk.defineCheckedProperty("false", "N");

Cheers,
Sudhaker
http://thej2ee.com (active again)
Sudhaker Raj
February 13,
To show 'Yes' and 'No' after checkbox :-)

var obj = new AW.UI.Grid; // your grid
...
...
var chk= new AW.Templates.Checkbox; // create checkbox template
chk.setContent("box/text", function() {return this.getControlProperty("value") ? "Yes" : "No"}); // magic here
obj.setCellTemplate(checkbox, 4); // fifth column is checkbox
...
document.write(obj); // write grid


Code posted above was bit confusing, so made it idiot-proof.

Cheers,
Sudhaker
http://thej2ee.com (active again)
Sudhaker Raj
February 13,
Excellent, thanks Sudhaker!

Just needed to change
obj.setCellTemplate(checkbox, 4); // fifth column is checkbox

to
obj.setCellTemplate(chk, 4); // fifth column is checkbox
Stuart
February 14,

This topic is archived.

See also:


Back to support forum