如何启用复选框 DLGIdentifier 的输入?

How to enable entry from the checkbox DLGIdentifier?

中,我展示了如何在更改复选框状态时启用条目。这次,我想创建多个条目,由相应的复选框控制。

对于每个复选框,我使用 DLGIdentifier 对其进行标记,然后使用 DLGEnabled(self.LookupElement("entryId"), self.LookupElement("cb_ID").DLGGetValue()) 来enable/disable 可以,但是失败 Q.Q 有人知道怎么解决吗?提前谢谢你。

这是我的代码。

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()
};

您可能希望将 SelectAction 方法替换为以下方法:

void SelectAction(object self, TagGroup tgItem){
        // tgItem is the taggroup of the element that fired the action
        // so no for-loop for checking all is needed here.
        // tgItem.TagGroupOpenBrowserWindow("",0)
        number checked = tgItem.DLGGetValue()
        string IDcheck
        if (!tgItem.DLGGetIdentifier(IDcheck)) return
        string IDField = "num2_" + right( IDcheck, len(IDcheck)-3 )
    
        // The DLGEnable() command only changes the taggroup of the dialog 
        // but doesn't do anything with the dialog window itself.
        // There is a separate command to enable/disable an element of the dialog.
        // void SetElementIsEnabled( ScriptObject dialogUI, String item_identifier, Boolean is_enabled )

        self.SetElementIsEnabled(IDField ,checked)
        return      
    };

In essence, you need different commands to change the displayed dialog. It is documented, but a bit hard to find: