Announcement

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

    custom valdators async condition function

    hello,
    I have defined a "promise" and a "async function" as follows.

    Code:
    function getCategoryType(categoryTypeID) {
            return new Promise(resolve => {           
                dsCategoryTypes.fetchData({ categoryTypeID: categoryTypeID, recordNumber: 1 }, function (dsResponse, data, dsRequest) {
                    resolve(data[0] || null);
                });             
            });
        }
        async function categoryTypeIsValid(item, validator, value, record) {
            var categoryType = await getCategoryType(record.categoryTypeID || null);
            if (categoryTypeID) {
                if (categoryTypeID.required === 1 && !value )
                    return false;
            } 
            return true;                
        }
    I made the fields validator definitions with await as follows.
    Code:
    isc.ListGrid.create({
    fields: [
    {name: "categoryType", type: "text", title: "Category Type" },
      {name: "documentNumber", title: "Document Number", type: "text",
            validators: [                                 
                        {
                            type: "custom", errorMessage: "Document number is required",
                            // when use async, validator don't work correctly
                            condition: async function (item, validator, value, record) {
                                var result =  await CategoryTypeIsValid(item, validator, value, record);
                                return result; 
                            }
                        }
                    ]
                }
    ]
    });
    The validation does not work correctly when using async property.
    How can I fix this issue?

    #2
    Use a serverCustom validator since the reason you need to go async is to go to the server.

    Comment

    Working...
    X