new Checkbox_A(parent, props)
Checkbox component that allows a single selection. Each checkbox can be separately checked or unchecked. This class focuses on the specific properties of the Checkbox component. Since it inherits from Accessor_A, all basic properties (e.g., height, width) are available but documented in the Accessor_A part.
| Name | Type | Description |
|---|---|---|
parent | HTMLElement | HTML element that is going to be the parent of the component |
props | TComponents. | Properties of the checkbox component. |
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();Extends
Members
checked :string
Sets the checked state for the checkbox.
- string
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Set the checkbox to checked state
checkbox.checked = true;color :string
Sets the color of the description label.
- string
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Set the color of the description label
checkbox.color = '#ff0000';enabled :boolean
Gets the enabled state for the component.
- boolean
- Overrides
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Set the checkbox to enabled state
checkbox.enabled = true;onChange :function
Sets the onChange event handler for the checkbox component. The handler can either be a string representing a function to be executed or a function itself.
- If you are using an arrow function, like
()=>{}, thethisproperty of the scope may not refer to the checkbox object. - If you are using string assignment to define code execution, the string should contain
only the body of the code (executable statements), not a complete function declaration. Therefore, including function keywords like function or async function is incorrect.
- Correct (Statements Only):
xx.onChange = "console.log('Action done.');" - Incorrect (Function Declaration):
xx.onChange = "function() { console.log('Action done.'); }"
- function
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Example 1: Using a string as the handler:
checkbox.onChange = "console.log(this.checked);"// Example 2: Using a function as the handler:
checkbox.onChange = function () {
console.log(this.checked);
};// Example 3: Using an arrow function as the handler:
// Note that the `this` context will not refer to the checkbox object
checkbox.onChange = () => {
console.log(checkbox.checked);
};selectedIndex :number
Sets the check box binding index.
- number
- Deprecated
- The interface has been deprecated.
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
checkbox.selectedIndex = 0;text :string
Sets the description text label for the checkbox.
- string
- Source
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Set the description text label
checkbox.text = 'Execute Task';value :string
it is unstable and its use is not recommended, sets the binding value of the checkbox.
- string
- Source
- To Do
- This is an experimental interface; it is unstable and its use is not recommended.
const checkbox = new TComponents.Checkbox_A(document.body, {
position: 'absolute',
zIndex: 1000,
text: 'Execute'
});
checkbox.render();
// Set the binding value
checkbox.value = 'execute';Methods
(protected) defaultProps() → {TComponents.CheckboxProps}
Returns the default values of class properties (excluding parent properties).
- Overrides
- Source
- The default properties of the checkbox component.
markup() → {string}
Returns the HTML markup for the component.
- Overrides
- Source
The HTML markup for the component.
- Type:
- string
onInit() → {void}
Initializes the component and sets up click event handling.
- Overrides
- Source
- Type:
- void
onRender() → {void}
Renders the component on the screen and applies the necessary styles and event listeners.
- Overrides
- Source
If an error occurs during rendering, it will throw an Error with a specific error code and message.
- Type
- Error
- Type:
- void