Reputation: 1075
I've got a dijit form checkbox inside an ondemand grid. The Ondemand grid is part of a dojo widget. I'd like to call one of the functions in the widget within the checkbox's on change event, but I cant seem to get a reference to the widget. Here is my code:
TicketUnMarkedSet: function (GridData) {
//set the unmarked ticket information
gridStore = new Memory({ data: GridData, idProperty: "ID" });
grid = new (declare([OnDemandGrid, DijitRegistry]))({
store: gridStore,
columns: {
CheckedOut: {
label: "CO",
renderCell: function (object, cell) {
var CO = true; // check the checked out check box based on data from db
if (object.CheckedOut == "No") {
CO = false;
}
var cellContent = domConstruct.create("div", {});
var cbox = new CheckBox({
checked: CO,
name: "idBox"
});
cbox.placeAt(cellContent);
on(cbox, "change", function (evt) {
var Staff = "No";
if (evt == true) {//check box is checked, flag ticket as checked out
Staff = cookie("LoggedInAs")
}
this.CheckOutTicket(Staff);//how to call CheckOutTicket function (this is the checkbox)
});
return cellContent;
}
},
..more columns
},
CheckOutTicket: function (Staff){
alert(Staff);
}
How can I get a reference to CheckOutTicket function ?
Thanks
Pete
Upvotes: 1
Views: 225
Reputation: 925
I'd suggest you to use dojo/topic to get what you want.
on(cbox, "change", function (evt) {
var Staff = "No";
if (evt == true) {//check box is checked, flag ticket as checked out
Staff = cookie("LoggedInAs")
}
topic.publish("CheckOutTicket", Staff);
});
And somewhere in your parent widget, for i.e. in postCreate
this.own(topic.subscribe("CheckOutTicket", this.CheckOutTicket));
Now you don't have to care about passing handler from parent to child widget and use global variables.
Upvotes: 0
Reputation: 1075
I found a workaround, but maybe not the best solution. On the postCreate Event I define a global variable referencing the widget, and then use that variable to call the function from inside the change event for the checkbox
Upvotes: 1