1

In my MVC application, I can display the error messages for all the inputs i.e. TextBoxFor, DropdownList, etc. However, by using the same approach, I cannot show validation error for Kendo().Editor() or Kendo().EditorFor(). I tried with ValidationMessage beside ValidationMessageFor, but it does not make any sense. What might the problem be?


View:

<script type="text/javascript"> 
$(function () {     
    //For using Kendo Validation:
    $("form").kendoValidator();
});
</script>


//Validation works for TextBoxFor, DropDownList, etc.:
@Html.LabelFor(m => m.Summary)
@Html.TextBoxFor(m => m.Summary, new { maxlength = 50, @class = "k-textbox"})
@Html.ValidationMessageFor(m => m.Summary)

//Validation DOES NOT work for Editor or EditorFor:
@Html.LabelFor(m => m.Description, new { maxlength = 1000, @class = "editor-label" })
@(Html.Kendo().Editor()
        //@(Html.Kendo().EditorFor(m=>m.Description) //Also tried with this
        .Name("Description")
        .HtmlAttributes(new { @class = "editor-field" })
        .Resizable()
        .Tools(tools => tools
        .Clear()
        .Bold().Italic().Underline().Strikethrough().FontColor()
        .JustifyLeft()
        .JustifyCenter()
        .JustifyRight()
        .JustifyFull()
        .InsertUnorderedList().InsertOrderedList()
        .Outdent().Indent()
        .CreateLink().Unlink()
        .TableEditing()
        .CleanFormatting()
        )
)
@Html.ValidationMessage("Description")
//@Html.ValidationMessageFor(m => m.Description) //Also tried with this


Here are the generated html code for the inputs above. The script field is related to the button of the editor:

<label for="Summary">Summary</label>
<input id="Summary" class="k-textbox k-invalid" type="text" value="" style="width:660px; " name="Summary" maxlength="50" data-val-required="Required field!.." data-val="true" aria-invalid="true">
<span id="Summary_validationMessage" class="val val-danger k-invalid-msg field-validation-error" data-for="Summary" data-valmsg-for="Summary" role="alert" style="display: inline;">


<label class="editor-label" maxlength="1000" for="Description">Description</label>
<table class="k-widget k-editor k-header k-editor-widget" cellspacing="4" cellpadding="0" role="presentation" style="width: 660px; height: 77px;" data-role="resizable">
<script>
jQuery(function(){jQuery("#Description").kendoEditor({"resizable":true,"tools":[{"name":"bold"},{"name":"italic"},{"name":"underline"},{"name":"strikethrough"},{"name":"foreColor"},
{"name":"justifyLeft"},{"name":"justifyCenter"},{"name":"justifyRight"},{"name":"justifyFull"},{"name":"insertUnorderedList"},{"name":"insertOrderedList"},{"name":"outdent"},
{"name":"indent"},{"name":"createLink"},{"name":"unlink"},{"name":"createTable"},{"name":"addColumnLeft"},{"name":"addColumnRight"},{"name":"addRowAbove"},{"name":"addRowBelow"},
{"name":"deleteRow"},{"name":"deleteColumn"},{"name":"cleanFormatting"});
</script>
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="Description" style="display: none;"></span>

Update: Here is the rendered html code of Kendo().Editor():

<td class="k-editable-area">
    <iframe class="k-content" frameborder="0" title="Editable area. Press F10 for toolbar." src="javascript:" "">
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="utf-8">
            <script>
                (function (d, c) { d[c]('header'), d[c]('article'), d[c]('nav'), d[c]('section'), d[c]('footer'); })(document, 'createElement');
            </script>
        </head>
        <body contenteditable="true" autocorrect="off">
            <br class="k-br">
        </body>
    </html>
</iframe>
<textarea id="Description" class="editor-field k-content k-raw-content k-valid" style="width: 660px; height: 140px; display: none;" rows="5" name="Description" cols="20" data-role="editor" autocomplete="off"></textarea>
<div class="k-resize-handle">
    <span class="k-icon k-resize-se"></span>
</div>
</td>
Sparky
  • 98,165
  • 25
  • 199
  • 285
Jack
  • 1
  • 21
  • 118
  • 236
  • Check the html your generating. I'm not familiar with `Kendo.DropDownList()` but it probably hides the ` –  Jun 26 '15 at 09:21
  • @StephenMuecke Hi Stephane. Actually I have a look at the generated html before asking the question, but did not understand what the problem is. So, could you have a look at pls? On the other hand, may it be releted to validating the outside the text area? – Jack Jun 26 '15 at 09:31
  • You mention `Kendo().DropDownList()` in your question but you have not shown any html relating to a dropdownlist, nor have you shown the html for the ` –  Jun 26 '15 at 10:16
  • @StephenMuecke I just wanted to give an example for saying Kendo().DropDownList() in order to show that there is no problem regarding to this component. On the other hand, Summary field id TextBoxFor() and Description field is Kendo().Editor(). Is it not clear? Or what should I post? – Jack Jun 26 '15 at 10:38
  • Now I am even more confused - in your question you say _"I **cannot** show validation error for Kendo().DropDownList()"_ but your last comment says _"there is no problem regarding to this component"_? –  Jun 26 '15 at 10:41
  • @StephenMuecke I am soo sorry Stephane :( I made a mistake and correct the first paragraph of the question. I meant **Kendo().Editor()**, not Kendo().DropDownList(). Sorry :( – Jack Jun 26 '15 at 10:45
  • OK (now it makes more sense). What validation attributes do you have on property `Description` (i.e. what error messages are you expecting) –  Jun 26 '15 at 10:47
  • Only `Required` attribute and I just want to show `Required` attribute and solving this problem also solves any other attributes if I need to use the other attributes. – Jack Jun 26 '15 at 10:57
  • View the page source and check if a –  Jun 26 '15 at 11:53
  • As you can see the last line on the html code, `style="display: none;"` for validation. – Jack Jun 26 '15 at 12:01
  • No I meant is there a ` –  Jun 26 '15 at 12:05
  • I added an update to the question. Yes, there is a ` – Jack Jun 26 '15 at 12:49
  • Try adding `$.validator.setDefaults({ ignore: ':hidden' });` - or `$.validator.setDefaults({ ignore: []});` depending on which version of jquery you have (note this is not the ideal solution - its just to test for the moment). Note this needs to be after `jqueryvalidate.unobtrusive.js` but not inside `$(function ()` –  Jun 26 '15 at 12:52
  • I tried them, but as I use [Kendo Validatior](http://docs.telerik.com/kendo-ui/aspnet-mvc/validation), it does not work. I think I need to find such a kind of property for [Kendo Validatior](http://docs.telerik.com/kendo-ui/aspnet-mvc/validation). Any idea? – Jack Jun 26 '15 at 14:11
  • On the other hand, I also tried with jquery validation, but it did not make any sense. – Jack Jun 26 '15 at 14:27
  • @StephenMuecke, `ignore: ':hidden'` and `ignore: []` are completely opposite user settings. `ignore: ':hidden'` is already the plugin's default setting since version 1.9 and it ignores all hidden elements (no validation). `ignore: []` tells it to ignore *nothing* (validates hidden elements). See: http://stackoverflow.com/a/8565769/594235 – Sparky Jun 26 '15 at 14:43
  • @Sparky Do not you have any idea for resolving the issue? – Jack Jun 26 '15 at 14:45
  • Although I've answered thousands of jQuery Validate questions, I know very little about ASP and unobtrusive validation. – Sparky Jun 26 '15 at 14:52
  • @Sparky, Oops, that was supposed to be `ignore: ''` –  Jun 26 '15 at 22:17
  • Thanks a lot both of you. I tried but it dış not work (actually I also tried this in my previous project and did not seem to work). Maybe I made a mistake, but I am not sure if there is only one way to use it onload function of jQuery. I wil retry again but if you have any idea with another options I would be appreciated if you share at here. Many thanks again. You are so helpful persons. Voted++ – Jack Jun 27 '15 at 00:13
  • @Christof, Found [this article](http://blogs.visoftinc.com/2013/01/14/making-the-kendo-ui-editor-work-with-jquery-validations/) which may be helpful –  Jun 27 '15 at 02:36
  • @StephenMuecke Many thanks for your effort. Yes, it was very helpful, but the only problem is to style the `validationmessage`. The validation message is diplayed just right side of the inputs, but it is displayed below the Editor. When I change the style for editor, the validation messages's positions are changed for the other inputs in that case. Can I define it for Editor separately? – Jack Jun 29 '15 at 11:19
  • Sorry, but I'm not familiar with `Kendo` so don't know. You could probably wrap the `EditorFor()` and `ValidationMessageFor()` inside a `div` with a specific `id` and then use css to style it - something like `#yourID span.field-validation-error { display: block; }` –  Jun 29 '15 at 11:29

0 Answers0