Announcement

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

    problem with ValuesManager and conditional required validator

    SmartClient Version: v13.1p_2025-01-18/AllModules Development Only (built 2025-01-18)

    Hello, please try the singleSourceValidation sample modified as in this testcase:

    Code:
     <DataSource isSampleDS="true"
        ID="supplyItem"
        serverType="sql"
        tableName="supplyItem"
        titleField="itemName"
        testFileName="/examples/shared/ds/test_data/supplyItem.data.xml"
        dbImportFileName="/examples/shared/ds/test_data/supplyItemLarge.data.xml"
    >
    
        <fields>
            <field name="itemID" type="sequence" primaryKey="true"/>
            <field name="itemName" type="text" title="Item" length="128" required="true"/>
            <field name="SKU" type="text" title="SKU" length="10" required="true"/>
            <field name="description" type="text" title="Description" length="2000">
            <validators>
                 <validator type="required">
                       <applyWhen fieldName="SKU" operator="isNull"/>
                 </validator>
               </validators>
            </field>
            <field name="category" type="text" title="Category" length="128" required="true"
                   foreignKey="supplyCategory.categoryName"/>
            <field name="units" type="enum" title="Units" length="5">
                <valueMap>
                    <value>Roll</value>
                    <value>Ea</value>
                    <value>Pkt</value>
                    <value>Set</value>
                    <value>Tube</value>
                    <value>Pad</value>
                    <value>Ream</value>
                    <value>Tin</value>
                    <value>Bag</value>
                    <value>Ctn</value>
                    <value>Box</value>
                </valueMap>
            </field>
            <field name="unitCost" type="float" title="Unit Cost" required="true">
                <validators>
                    <validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost"/>
                    <validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2"/>
                </validators>
            </field>
            <field name="inStock" type="boolean" title="In Stock"/>
            <field name="nextShipment" type="date" title="Next Shipment"/>
        </fields>
    
    
    </DataSource>
    Code:
    isc.ValuesManager.create({
        ID: "vm",
        dataSource: "supplyItem"
    })
    
    isc.DynamicForm.create({
        ID: "dynamicForm",
        valuesManager: "vm",
        fields:[
    {name:"itemName"}
    ]
    });
    
    isc.IButton.create({
        ID: "saveButton",
        title: "Save",
        click: "vm.saveData()"
    });
    
    
    isc.IButton.create({
        ID: "clearErrorsButton",
        title: "Clear Errors",
        click: "dynamicForm.clearErrors(true)"
    });
    
    isc.IButton.create({
        ID: "disableValidationButton",
        autoFit: true,
        title: "Disable Validation",
        click: function () {
            dynamicForm.disableValidation = !dynamicForm.disableValidation;
            this.setTitle((dynamicForm.disableValidation ? "Enable" : "Disable")+" Validation");
        }
    });
    
    isc.HStack.create({
        ID: "buttons",
        height: 24,
        membersMargin: 10,
        members: [saveButton, clearErrorsButton, disableValidationButton]
    });
    
    isc.VLayout.create({
        membersMargin: 10,
        members: [dynamicForm, buttons]
    });
    
    vm.fetchData({SKU:90600})
    If you run it and click 'Save', you won't see a request. In fact, vm.getErrors() will indicate that the description is required. However, the applyWhen condition isn't satisfied, so I didn't expect this. Is it a bug, or am I missing something?
    Last edited by claudiobosticco; 20 Jan 2025, 08:52.

    #2
    Good catch, Claudio. If the SKU had been included in any member form of the ValuesManager, the applyWhen criteria would have been respected. However, in this case while validating the remaining DataSource fields, the check for applyWhen was not applied. This has been fixed for builds starting on 24 January.

    Comment


      #3
      SmartClient Version: v13.1p_2025-01-25/Enterprise Deployment (built 2025-01-25)

      Hello, regarding the test case, it is fixed, thanks. In my application I've got a validator with two criterion in the applyWhen, and I noticed that if I write the validator like this:

      Code:
      <validators>
           <validator type="required">
                   <applyWhen fieldName="TIPOLOGIA_ATTIVITA" operator="equals" value="EVENTO"/>
                    <applyWhen fieldName="TIPO_EVENTO" operator="equals" value="GARA"/>
           </validator>
        </validators>
      it won't work, ie the field will be required even if the two applyWhen criterion evaluates to false, but if I write it like this:

      Code:
      <validators>
          <validator type="required">
              <applyWhen operator="and">
                  <criteria>
                      <criterion fieldName="TIPOLOGIA_ATTIVITA" operator="equals" value="EVENTO"/>
                      <criterion fieldName="TIPO_EVENTO" operator="equals" value="GARA"/>
                  </criteria>
              </applyWhen>
          </validator>
      </validators>
      then it works. Is it expected?

      Comment


        #4
        Yes, that is expected. 'applyWhen' is not defined as a multi-value element but rather expects a single AdvancedCriteria object.

        Comment

        Working...
        X