Check status of CInput("checkbox") changes from checked to unchecked after few seconds automatically

XMLWordPrintable

    • Type: Incident report
    • Resolution: False Positive
    • Priority: Trivial
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Steps to reproduce:

      1. Adding the following code for creating in CInput("checkbox") element in widget.view.php
         <?php
            $powerLabel    = new CLabel("Power On/Off", "powerLabel");
            $powerLabel->addStyle("margin-left: 10px;");
            $powerLabel->addStyle("margin-right: 3px;");
            $powerCheckbox = new CInput("checkbox", "powerCheckbox", "on");
            $powerCheckbox->setId("powerCheckbox");
            $powerDiv      = new CDiv([$powerLabel, $powerCheckbox]);
            $widgetView = new CWidgetView($data);
            $widgetView->addItem($powerDiv);
            $widgetView->show();
        
      2. Adding the following handling check status of CInput("checkbox") in class.widget.js 
        class WidgetAirConditioner  extends CWidget {
            static powerCheckboxChanged() {
                const powerCheckbox = document.getElementById('powerCheckbox');
                    if (powerCheckbox) {
                        if (powerCheckbox.checked) {
                            console.log('Checkbox is checked.');
                        } else {
                            console.log('Checkbox is unchecked.');
                        }
            }
        
            onInitialize() {
            }
            
            onResize() {
            }
        
            processUpdateResponse(response) {
                super.processUpdateResponse(response);
            }
            
            promiseReady() {
                return super.promiseReady();
            }
            
            setContents(response) {
                super.setContents(response);
        
                const powerCheckbox = document.getElementById("powerCheckbox");
                if (powerCheckbox) {
                    powerCheckbox.addEventListener('change', WidgetHitachiAirConditioner.powerCheckboxChanged);
                }
            }
            
            onClearContents() {
            }
        }
        

      Result:
      Check status of powerCheckbox is checked after user presses powerCheckbox. But after few seconds,  Check status of powerCheckbox is not checked.
      Expected:
      Check status of powerCheckbox is checked after user presses powerCheckbox. And after few seconds,  Check status of powerCheckbox is still checked.

        1. power on.png
          14 kB
          snow uyl
        2. power off.png
          14 kB
          snow uyl
        3. Zabix-7.0.6.png
          17 kB
          snow uyl
        4. image-2024-12-12-09-37-08-117.png
          3.63 MB
          Andrejs Verza
        5. image-2024-12-12-09-37-08-986.png
          3.63 MB
          Andrejs Verza
        6. image-2024-12-12-09-37-11-060.png
          3.63 MB
          Andrejs Verza
        7. air_conditioning_widget.tar.gz
          0.5 kB
          snow uyl

            Assignee:
            Zabbix Support Team
            Reporter:
            snow uyl
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: