Mych Mych - 4 months ago 36
jQuery Question

How to check for an empty Telerik Kendo editor content

I have a simple form with a couple of dropdowns a multi-select and an editor.
The dropdowns both have an initial item which has a text value of Please Select and a value of ''. On submission I have the following bit of Javascript/JQuery that checks that I have values in my dropdowns, multi-select and editor.

var validFlag = true;

var dropdownlist = $("#addNew_dTeam").data("kendoDropDownList");
if (dropdownlist.value() == "") {
validFlag = false;
errorMsg = "<li>Select Team</li>"
}

dropdownlist = $("#addNew_dType").data("kendoDropDownList");
if (dropdownlist.value() == "") {
validFlag = false;
errorMsg += "<li>Select Entry Type</li>"
}

var multiSelect = $("#msServers").data("kendoMultiSelect");
if (multiSelect.value() == "") {
validFlag = false;
errorMsg += "<li>Add at least one Server or select N/A</li>"
}

var editor = $("#diaryComments").data("kendoEditor");
if (editor.value() == "") {
validFlag = false;
errorMsg += "<li>A comment is mandatory</li>"
}


The code works fine for the dropdowns and multi-select, but the check for empty editor content does not work. My editor is empty yet the if (editor.value() == "") is not true.

Answer

While editor is empty, consider one blank space so your condition will be like if (editor.value() == ' ') (there is one space between single quote)...

Demo

hope so it will work for you...

Comments