Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2745
Programmatically set an editor as required based on selection changed event
posted

I have an igGrid and on the edit cell starting event I am hooking into the SelectionChanged event of an igCombo control of one of the columns.  Based on the value that the user selects, I need to require a field in the grid.  That being said, here's the code:

$("#ItemsGrid").on("iggridupdatingeditcellstarting", function (e, ui) {
    var row = $("#ItemsGrid").igGrid("findRecordByKey", ui.rowID);

    if (ui.columnKey === 'Description') {
        $(ui.editor).igCombo("option", "dataSource", row.Descriptions);
        $(ui.editor).igCombo("option", "dataBind");

        $(ui.editor).on("igcomboselectionchanged", function (e, list) {
            var row = $("#ItemsGrid").igGrid("findRecordByKey", ui.rowID);

            $.each(row.Descriptions, function () {
                if (this.Description === row.Description) {
                    var editorCuft = $("#ItemsGrid").igGridUpdating("editorForKey", "Cuft");
                    var editorDensity = $("#ItemsGrid").igGridUpdating("editorForKey", "Density");

                    var isCuftRequired = editorCuft.igTextEditor("option", "required");
                    var isDensityRequired = editorDensity.igTextEditor("option", "required");

                    return false;
                };
            });
        });

        return row.Descriptions.length != 1; // No editing for entries that contain one single option
    }
});

The problem I am having is that isCuftRequired is not returning the expected bool value but rather the editor itself. I've tried the following:

$(editorCuft).igTextEditor("option", "required");
editorCuft.igTextEditor("option", "required");

In theory I'd should be able to set the value and have the UI reflect the change if the user decides not to enter a value. For example:

$(editorCuft).igTextEditor("option", "required", this.RequiresCuft);
$(editorDensity).igTextEditor("option", "required", this.RequiresDensity);

But I cannot hook into the correct object to do so.

Thoughts?

  • 2745
    Verified Answer
    Offline posted

    I don't like the solution but this does work:

     

    var editorCuft = $("#ItemsGrid").data("igGridUpdating").editorForKey("Cuft");
    
    editorCuft.data("igEditor").options.required = true;
    editorCuft.igEditor("option", "validatorOptions", { required: true, onsubmit: true, onblur: true });
    

    The API should be able to let me set this through methods but it isn't working. This does work, but I fear it may have reprecussions. Until I have a true solution, this workaround will have to do.