This is a migrated thread and some comments may be shown as answers.

[Solved] Unobtrusive validation don't works

2 Answers 160 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tetha
Top achievements
Rank 1
Tetha asked on 08 Aug 2011, 10:03 AM
Hello,
I have a Combobox binded to Model field and I want to use unobtrusive validation included with mvc 3.
This is the code:
<div class="formField">
    @(Html.Telerik().ComboBoxFor(m => m.regioneID)
                .ClientEvents(events =>
                {
                    events.OnChange("onComboboxRegioneChange");
                })
                            .BindTo(new SelectList(Anagrafiche.LoadRegioni(), "regioneID", "Descrizione"))
                        .InputHtmlAttributes(new { style = "width: 100px" })
                                .HtmlAttributes(new { style = "width: 120px" })
                                    )
    @Html.ValidationMessageFor(model => model.regioneID)
</div>
The problem is that the client validation isn't performed.
Looking the code I find that the validation attributes are not associated with combobox control.
The output:
<div class="formField">
 
    <div class="t-widget t-combobox t-header" style="width: 120px"><div class="t-dropdown-wrap t-state-default"><input class="t-input" id="regioneID-input" name="regioneID-input" style="width: 100px" type="text" /><span class="t-select t-header"><span class="t-icon t-arrow-down">select</span></span></div><input id="regioneID" name="regioneID" style="display:none" type="text" /></div>
 
    <span class="field-validation-valid" data-valmsg-for="regioneID" data-valmsg-replace="true"></span>
 
</div>
Thank you in advance.

Mirko

2 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 09 Feb 2012, 04:21 PM
I have the exact same issue.  I'm decorating TagsInput with [Required] but data-val-required attribute is not generated.  Another Html.EditorFor on the same form is generating the required attribute, so this seems like a bug with Telerik().AutoCompleteFor().  Here's my code:

@(Html.Telerik().AutoCompleteFor(model => model.TagsInput)
                .BindTo(Model.Tags)
                .Name("MyTags")
                .Encode(false)
                .AutoFill(true)
                .HtmlAttributes(new { style = "width: 100%;" })
                .HighlightFirstMatch(true)
                .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.StartsWith))
                .Multiple(multi => multi.Separator(", ").Enabled(true))
 )
@Html.ValidationMessageFor(model => model.TagsInput)
0
Alex
Top achievements
Rank 1
answered on 09 Feb 2012, 05:14 PM
Ok, never mind.  It way my fault.  Had to remove
.Name("MyTags")
Nothing to see here.  Carry on :)
Tags
ComboBox
Asked by
Tetha
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or