mardi 7 septembre 2021

How to enable entry from the checkbox DLGIdentifier?

In the previous question, I showed how to enable the entry while changing checkbox state. This time, I want to create multiple entries which are controlled by the corresponding checkbox.

For each checkbox I used DLGIdentifier to label it, then used DLGEnabled(self.LookupElement("entryId"), self.LookupElement("cb_ID").DLGGetValue()) to enable/disable it, but it fails Q.Q Does Anyone know how to solve it? Thank you in advance.

Here is my code.

class TestUI : UIFrame{
    number true, false, n_items
    
    TestUI(object self){
        true=1; false=0;
        result("TestUI ["+self.ScriptObjectGetID()+"] constructed\n")
    };
    
    ~TestUI(object self){
        result("TestUI ["+self.ScriptObjectGetID()+"] destructed\n")
    };
    
    void SelectAction(object self, TagGroup tgItem){
        for(number i=0;i<n_items;i++){
            // change state, but it failed.
            DLGEnabled(self.LookupElement("num2_"+(i+1)),self.LookupElement("cb_"+(i+1)).DLGGetValue())
            // the values of each checkbox are retured correctly.
            result(i+":"+self.LookupElement("cb_"+(i+1)).DLGGetValue()+"\n")
        };
    };
    
    TagGroup InputGenerator(object self, number i){
        // Entry template
        TagGroup tgBox = DLGCreateBox("Box_"+(i+1))
        
        TagGroup tgLable = DLGCreateLabel("#")
        // each elements are using DLGIdentifier to label it
        TagGroup tgNumber1 = DLGCreateRealField(10,5,0).DLGIdentifier("num1_"+(i+1))
        TagGroup tgNumber2 = DLGCreateRealField(10,10,0).DLGIdentifier("num2_"+(i+1))
        TagGroup tgGroup = DLGGroupItems(tgLable,tgNumber1,tgNumber2).DLGTableLayout(3,1,0)
        tgBox.DLGAddElement(tgGroup)
        
        TagGroup cb = DLGCreateCheckBox("IsCheck", false,"SelectAction").DLGIdentifier("cb_"+(i+1))
        tgBox.DLGAddElement(cb)
        DLGEnabled(tgNumber2,cb.DLGGetValue())
        
        return tgBox
    }
    
    void CreateDialog(object self){
        TagGroup main = DLGCreateDialog("Test")
        n_items = 3
        for (number j=0; j<n_items; j++){
            //create multiple entries by for loop
            TagGroup item=self.InputGenerator(j)
            main.DLGAddElement(item)
        };
        self.init(main).Display("TestUI")
    };
};

{
    alloc(TestUI).CreateDialog()
};



Aucun commentaire:

Enregistrer un commentaire