1

In Slickgrid inline edit, we try to validate the data based on some criteria. But criteria check need some modified or existing data from database. so before validate will fetch the criteria needed data from database. This data fetch process is async process. After this async process completion will given the data validate status. Based on that validation status our custom validation should works. As we expected.

So this scenario we tried the following code blocks. But it is not working as our expectation. Because async process is not available in custom validator.

column definition:

[{
    id:'project_name',
    nameKey:'Project Name',
    field:'project_name',
    sortable: true,
    type: FieldType.string,
    filterable: true,
    filter: {
        model: Filters.compoundInput
    },
    cssClass: 'left-align',
    editor: {
        model: Editors.longText,
        validator: ProjectValidator
    }
}]

Custom Validation Menthod:

ProjectValidator = (value: any, args?: EditorArguments) => {
    let queryTerm = value;
    return this.queryProjects(queryTerm).then(response=>{ // Checking the project name exist in database
        if(response['status']=='ALREADY_EXIST'){
            return { valid: false, msg: 'Entered project name existing in database. Please enter unique project.' };    
        }
        return { valid: true, msg: '' };
    })
}

So kindly guide me to achieve this async custom validation in slickgrid inline edit feature.

hari
  • 47
  • 2
  • 1
    I took a quick look at SlickGrid's source-code and the calls to `column.validator` are nested deeply and entirely synchronous, so in short: _it isn't possible_ to use async code here. – Dai Dec 14 '21 at 05:01
  • 1
    However, **what you're wanting to do is not actually validation: it's verification**. Validation and Verification are separate concerns. "Validation" is meant to be _fast_, such as checking only _static and invariant constraints_, like a regex. "Verification" is intended to to take longer (and should be done in the context of a database transaction, imo). That said, I don't know how to add async verification support to SlickGrid, sorry. – Dai Dec 14 '21 at 05:02
  • Following what @Dai already wrote (great comments), all validation in SlickGrid are synchronous processes, the internal code doesn't support async validation. The only possible solution that I can imagine would be to remove SlickGrid editing and instead create your own modal window with a form that you have full control over, do your stuff (validation & everything) and once you're done and hit Save and it will then push the data back to SlickGrid. Also note that I'm the author of Angular-Slickgrid which is a wrapper on top of SlickGrid (which itself was created by another great developer). – ghiscoding Dec 14 '21 at 16:08
  • 1
    Personally, I have a save button which checks the validity before saving to the server and returns a message if the data doesn't pass. You could get it to return an object with specific messages for rows and columns, and then apply formatting to the grid cells appropriately. If you do want instant feedback while editing, then you could kick off an event (not part of the validator code) which applies the formatting when it returns. – Ben McIntyre Dec 15 '21 at 01:25

0 Answers0