cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Open/Close The Dialog Box depend on some variable value

Open/Close The Dialog Box depend on some variable value

Hemingway
Established Member

Hello, how to implement the local script for the Dialog Box behavior? F.e. when some var > 50: -> Open the Dialog Box,  <= - automatically Close. Thank you in advance. 

5 REPLIES 5

Sgilk
Frequent Contributor

Hi @Hemingway ,

Is this for a WebIQ HMI?

Hemingway
Established Member

Yes, I'm using WebIQ. 

Sgilk
Frequent Contributor

Something like this should work for you. I have a dialogbox widget named "myDialog" opening/closing based on the state of a process variable "bTest". In my local script, I have the following code...

 

    module.run = function (self) {
        dialog = shmi.ctrl(".myDialog");

        im = shmi.requires("visuals.session.ItemManager");
        let tok = null;

        tok = im.subscribe(["bTest"], (name,value)=>{
            console.log(`New value for item ${name}: ${value}`);
            if(value){
                dialog.show();
            } else {
                dialog.hide();
            }
        });

        /* called when this local-script is disabled */
        self.onDisable = function () {
            tok.unlisten();
            self.run = false; /* from original .onDisable function of LocalScript control */
        };
    };

 

@CodeShepherd , please move to WebIQ sub.

webiq-sk
Frequent Contributor

Just a quick note: you should refrain from using shmi.ctrl and only use shmi.onReady as WebIQ is an asynchronous system which means that when your LocalScript runs the dialog might not have been initialized yet so your script would fail. However, it could work perfectly on your system, but on another system or when there is a slow network connection it could fail. That's why you should never rely on "it works on my machine with shmi.ctrl".

Therefore you should always and only use shmi.onReady as shown in this example:
https://demo.smart-hmi.com/demo-animation/js/custom-libs/local-scripts/shapeRotationExample.js

Also, you should not use "dialog = " and "im =", because this would create global JavaScript variables which is usually not intended. You should also prefix those with a "const ".

Moved to corresponding forum Smart HMI - WebIQ Designer and Server.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist