patternjavascriptMinor
Adding a checkbox to a JavaScript class object
Viewed 0 times
javascriptcheckboxaddingobjectclass
Problem
I'm working on adding checkbox functionality that controls adding new checkboxes to a
I just need basic class object in JavaScript to be created to track just whether its checked, visible, or disabled. In my case when its disabled it will not be checked, but may change in a later release. I've looked at GWT and ZWT JavaScripting libraries and they seem too complicated. Is there a simple solution I can do myself?
Looking for some constructive criticism, a good link or two for reference, and perhaps an estimate on whether this is feasible and how would I add a checkbox to the class below, and do I also have to worry about adding events to this? And what would be the best way to track multiple famous people in this example: a list, an array, or another class? I'm thinking a dynamic array of some kind.
```
// Constructor for dynamic checkbox classes
var FamousPerson = function (id, checkStatus, visibleStatus, enabledStatus) {
this.id = id; // primary key for a person for a specific row
this.checkStatus = checkStatus;
this.visibleStatus = visibleStatus;
this.enabledStatus = enabledStatus;
}
FamousPerson.prototype.getId() = function () {
return this.id; // id is reference stored in xml or database row
};
FamousPerson.prototype.update = function (checkStatus, visibleStatus, enabledStatus) {
// note: don't update id
this.checkStatus = checkStatus; // boolean 0 is not checked, 1 is checked
this.visibleStatus = visibleStatus; // boolean 0 is not visible, 1 is visible
this.enabledStatus = enabledStatus; // boolean 0 is not
div element as well a tracking checkbox behavior. My goal is to make this dirt simple. I've noticed that there is some JavaScript function prototypes for creating objects such as checkboxes and also controlling basic behavior such as visibility, whether its checked or disabled and maybe even adding a label or image next to the checkbox. My plan is to add this to an array or list and how can this be done?I just need basic class object in JavaScript to be created to track just whether its checked, visible, or disabled. In my case when its disabled it will not be checked, but may change in a later release. I've looked at GWT and ZWT JavaScripting libraries and they seem too complicated. Is there a simple solution I can do myself?
Looking for some constructive criticism, a good link or two for reference, and perhaps an estimate on whether this is feasible and how would I add a checkbox to the class below, and do I also have to worry about adding events to this? And what would be the best way to track multiple famous people in this example: a list, an array, or another class? I'm thinking a dynamic array of some kind.
```
// Constructor for dynamic checkbox classes
var FamousPerson = function (id, checkStatus, visibleStatus, enabledStatus) {
this.id = id; // primary key for a person for a specific row
this.checkStatus = checkStatus;
this.visibleStatus = visibleStatus;
this.enabledStatus = enabledStatus;
}
FamousPerson.prototype.getId() = function () {
return this.id; // id is reference stored in xml or database row
};
FamousPerson.prototype.update = function (checkStatus, visibleStatus, enabledStatus) {
// note: don't update id
this.checkStatus = checkStatus; // boolean 0 is not checked, 1 is checked
this.visibleStatus = visibleStatus; // boolean 0 is not visible, 1 is visible
this.enabledStatus = enabledStatus; // boolean 0 is not
Solution
In my opinion, it seems like this should be it's own class. You should have another object to control the
As for the solution part, if you still want to add it in here, check out this. There's an example of creating a checkbox with a label and adding it to the DOM. Shouldn't be too hard to patch some of it in to your existing class.
FamousPerson objects and add them when they are instantiated. I would also decouple the checkbox from the FamousPerson class itself and tie the behavior in elsewhere. As for the solution part, if you still want to add it in here, check out this. There's an example of creating a checkbox with a label and adding it to the DOM. Shouldn't be too hard to patch some of it in to your existing class.
Context
StackExchange Code Review Q#11569, answer score: 3
Revisions (0)
No revisions yet.