Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    setReadOnlyWhen does not work with ValuesManager

    Hello,
    Don't now if this is desired but when conditions work only with fields available in current DynamicForm and not with whole Record and multiple DynamicForms connected with ValuesManager.
    Or maybe there is a switch to enable field to be evaluated in global scope?

    See this test case:
    Code:
            DataSource ds = new DataSource();
            ds.setClientOnly(true);
    
            DataSourceIntegerField fieldId = new DataSourceIntegerField("id");
            fieldId.setPrimaryKey(true);
            ds.addField(fieldId);
            ds.addField(new DataSourceTextField("field1"));
            ds.addField(new DataSourceTextField("field2"));
    
            DataSourceTextField fieldStatus = new DataSourceTextField("status");
            fieldStatus.setValueMap("new", "progress", "finished");
            ds.addField(fieldStatus);
    
            VLayout layout1 = new VLayout(5);
            layout1.setGroupTitle("vm1");
    
            ValuesManager vm1 = new ValuesManager();
            vm1.setDataSource(ds);
    
            DynamicForm form1 = new DynamicForm();
            form1.setDataSource(ds);
            form1.setValuesManager(vm1);
    
            TextItem itemField1 = new TextItem("field1");
            itemField1.setReadOnlyWhen(new AdvancedCriteria("status", OperatorId.IN_SET, new String[] {"finished"}));
    
            SelectItem itemStatus = new SelectItem("status");
            itemStatus.setRedrawOnChange(true);
    
            form1.setFields(
                    new TextItem("id"),
                    itemField1,
                    itemStatus
            );
            layout1.addMember(form1);
    
            DynamicForm form2 = new DynamicForm();
            form2.setDataSource(ds);
            form2.setValuesManager(vm1);
    
            TextItem itemField2 = new TextItem("field2");
            itemField2.setReadOnlyWhen(new AdvancedCriteria("status", OperatorId.IN_SET, new String[] {"finished"}));
    
            form2.setFields(
                    itemField2
            );
            layout1.addMember(form2);
    
            this.addChild(layout1);
    When setting status field to finished `field1` item becomes readonly but `field2` does not.

    Is there a way to use values from whole Record in this condition? Tried `setRedrawOnChange` but with no luck.

    Best regards
    Mariusz Goch


    #2
    Interesting case, and as one of our very smartest users we're happy to see you getting into these more advanced, declarative features!

    The definite way to resolve this is to reference the values via the DataSource instead of the local "status" reference. In this case you didn't give the DataSource an ID but of course you could do, even if it's a generated one. Then, you could refer to the "status" value via the dataSourceId.fieldName format.

    https://smartclient.com/smartclient-...nvas.ruleScope

    However, it seems natural that a non-qualified identifier like "status" should, in a ValuesManager be allowed as a way to refer to a value that appears anywhere in that ValuesManager. We will look at making this possible.

    Comment


      #3
      Thank you for your response.

      With DataSource ID it works like a charm and of course it will be great if it will be possible to work without it.

      Best regards
      Mariusz Goch


      Comment


        #4
        I think I misunderstood.

        If you meant something like this:
        Code:
        itemField1.setReadOnlyWhen(new AdvancedCriteria(ds.getID() + ".status", OperatorId.IN_SET, new String[] {"finished"}));
        It works only in very simple test case when only one record of this DataSource can be edited at the same time.

        For example I have multiple tabs app and a user can open 2 separate records. That provides to use rules for last opened record to all forms.

        I've tried to access by ID of ValuesManager but it does not contain getRuleContext() so I assume it does not provide any rules.

        There is also a strange thing, when I call from console:
        Code:
        isc_DynamicForm_9.getRuleContext();
        on two forms which are editing two separate records only data from last one opened is returned in a structure.

        Am I missing something?
        Is there a way to get rules from ValuesManager by ID or am I going wrong way?

        Best regards
        Mariusz Goch

        Comment


          #5
          It's likely that we're just going to make your original code work, but, you can use isRuleScope to make it so that each tab maintains a separate ruleScope. That way, DataSource-based references to the values of the record should work, and won't conflict with other tabs.

          Comment


            #6
            We have added support for the short-form field references in rule criteria to match against the field value in any of the ValuesManager member forms so your initial test case should now work without change. This change has been applied back to version 12.1 and is available in builds starting on May 5.

            Comment


              #7
              Hi,

              I've tested on build from 2023-05-06 and it works great.
              Thank you for quick fix.

              Best regards
              Mariusz Goch

              Comment

              Working...
              X