Inline editor with selectize validtion

Inline editor with selectize validtion

tdktdk Posts: 32Questions: 16Answers: 0

Hi,

I have my editor configured like this with validation on PreSubmit. However the problem is that editor.field( "ProjectId" ) is always empty when performing the validation checks.

How can I validate a selectize DDL with inline editing?

 editor = new $.fn.dataTable.Editor({
        ajax: {
            type: "POST", url: "/WorkDiary/SaveDetail",dataType: "json",contentType: "application/json",processData: "false",
            data: function(d) {return JSON.stringify(d);}
        },
        table: "#detailTable",
        idSrc: "Id",
        fields: [
            { label: "Id:", name: "Id", type: "readonly" },
            { label: "WorkDiaryId:", name: "WorkDiaryId", type: "readonly" },
            { label: "Time:", name: "WorkTime", type: "readonly" },
            { label: "Activity:", name: "Activity", type: "textarea" },
            {
                label: "Project",
                name: "ProjectId",
                type: "selectize",
                opts: {
                    valueField: "Id",
                    labelField: "Name",
                    searchField: "Name",
                    preload: true,
                    maxItems: 1,
                    load: function(query, callback) {
                        $.ajax({
                            url: "/SelectHelper/GetProjectList",
                            type: "GET",
                            dataType: "json",
                            data: { q: query },
                            error: function() { callback(); },
                            success: function(res) { callback(res); }
                        });
                    }
                }
            },
            { label: "DateCreated:", name: "DateCreated", type: "readonly"  },
            { label: "CreatedBy:", name: "CreatedBy", type: "readonly"  }
        ],
        formOptions: { inline: { onBlur: "submit", submit: "all" } },
        i18n: { edit: { title: "Diary Form" } }
    });

     editor.on( "preSubmit", function ( e, d, action ) {
         if ( action !== "remove" ) {
            var projectId = editor.field( "ProjectId" );
            if ( !projectId.isMultiValue() ) {
                if ( !projectId.val() || projectId.val() === 0 )
                    projectId.error("You must select a project");
            }
            if ( this.inError() ) { 
                return false;
            }
        }

Answers

This discussion has been closed.