Вопрос

I have custom validation on some grid components (rangeFrom & rangeTo)

if any of the validation fails, I would like to set markDirty to true so that the field that is invalid is displayed in an error state and a user can see what field is wrong.

if (record.get("type") === "ROW_HEIGHT" && record.get("apply_before") === true)
    {
        var rangeFrom = record.get("range_from");
        var rangeTo = record.get("range_to");           

        if ((rangeFrom !== "") && (rangeTo !== "")) {
            if ((rangeFrom.match(/[^0-9]+$/) !== null) || (rangeTo.match(/[^0-9]+$/) !== null)) {
                if (rangeFrom.match(/[^0-9]+$/) !== null){

                                    **MARK rangeFrom Dirty here**   

                }
                isValid = false;
            }
            else if (rangeFrom > rangeTo) {
                isValid = false;
            }
            else if ((rangeFrom < "2") || (rangeTo < "2"))
                isValid = false;
        }
        else if ((rangeFrom === "") || (rangeTo === "") || (rangeFrom === null) || (rangeTo === null)) {
                isValid = false;
            }
        else
            isValid = true;

basically, any time validation fails (when isValid = false) I would like to mark rangeFrom or rangeTo dirty, depending on which field contains invalid values.

current validation accepts any entry that is numeric >= 2 if nothing(blank/null) or anything beside a number >= 2 is entered, the field should be marked dirty.

Это было полезно?

Решение 2

I found the answer to my question. Here is how I have it working for cell validation inside a grid component. This will check for validation and mark a single cell in the grid as invalid

        if (record.get("type") === "ROW_HEIGHT" && record.get("apply_before") === true)
    {
        var rangeFrom = record.get("range_from");
        var rangeTo = record.get("range_to");
        if ((rangeFrom !== "") && (rangeTo !== "")) {
            if ((rangeFrom.match(/[^0-9]+$/) !== null) || (rangeTo.match(/[^0-9]+$/) !== null)) {
                var store = MrEditor.excelLayout.overrideColumnGrid.getStore();
                var view = MrEditor.excelLayout.overrideColumnGrid.getView();
                var error = false;
                var rangeFromFailed = false;
                var rangeToFailed = false;
                var columnLength = MrEditor.excelLayout.overrideColumnGrid.columns.length;
                    for (var i = 0; i < columnLength; i++) {
                        var cell = view.getCellByPosition({row: idx, column: i});
                        cell.removeCls("x-form-invalid-field");
                        cell.set({'data-errorqtip': ''});
                        var fieldName = MrEditor.excelLayout.overrideColumnGrid.columns[i].dataIndex;
                        if (fieldName === 'range_from') {
                            rangeFromFailed = false;
                            if (rangeFrom.match(/[^0-9]+$/) !== null)
                                rangeFromFailed = true;
                            if (rangeFromFailed) {
                                cell.addCls("x-form-invalid-field");    //add default invalid styling to fcell in error state
                                cell.set({'data-errorqtip': 'Range From must be NUMERIC'});   //custom error message
                                error = true;
                            }
                        }
                        else if (fieldName === 'range_to') {
                            rangeToFailed = false;
                            var cell = view.getCellByPosition({row: idx, column: i});
                            if (rangeTo.match(/[^0-9]+$/) !== null)
                                rangeToFailed = true;
                            if (rangeToFailed) {
                                cell.addCls("x-form-invalid-field");    //add default invalid styling to fcell in error state
                                cell.set({'data-errorqtip': 'Range To must be NUMERIC'}); //custom error message
                                error = true;
                            }
                        }
                    }
                isValid = false;
            }

Другие советы

you need the td cell for the record field and then add following class x-grid-dirty-cell:

var node = grid.getView().getNode(record);
Ext.query('td:nth-child(x)', node).className += ' x-grid-dirty-cell'; // x is the column-index
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top