我嘗試使用Kendo編寫嚮導表單,例如sample。我在模型和兩個單選按鈕中添加了一個新屬性「性別」,並將其放入_RegistrationStep1.html 如果我不選擇任何單選按鈕,驗證對於性別不起作用。我沒有關於使用custom validatorKendo單選按鈕驗證不能在標籤條中工作
public class RegisterViewModel
{
[Required]
public short? Gender { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
}
的index.html:
<div class="row">
<div class="col-xs-8">
@(Html.Kendo().ProgressBar()
.Name("profileCompleteness")
.Type(ProgressBarType.Value)
.ShowStatus(false)
.Min(0)
.Max(4)
.Value(1)
)
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" , id="myForm" }))
{
@Html.AntiForgeryToken()
@(Html.Kendo().TabStrip()
.Name("tabstrip")
.Items(tabstrip =>
{
tabstrip.Add().Text("Account Setup")
.Selected(true)
.Content(m => Html.Partial("_RegistrationStep1", m));
tabstrip.Add().Text("Submit")
.Enabled(false)
.Content(m => Html.Partial("_RegistrationStep4", m));
})
.Events(ev =>
{
ev.Select("onSelect");
ev.Show("onShow");
})
)
}
</div>
</div>
@section Scripts {
<script>
var progress,
tabs,
currentIndex = 0;
$(document).ready(function() {
progress = $("#profileCompleteness").data("kendoProgressBar");
tabs = $("#tabstrip").data("kendoTabStrip");
})
function onSelect(e) {
var selectedIndex = tabIndexOfElement(e.item),
isMovingBack = selectedIndex < currentIndex;
if (isMovingBack || isTabValidAt(currentIndex)) {
console.log("tab passed validation")
currentIndex = selectedIndex;
tabs.enable(getTabAtIndex(currentIndex), true);
}
else {
e.preventDefault();
}
}
function onPreviousClick(e) {
e.preventDefault();
tabs.select(tabs.select().prev());
}
function onNextClick(e) {
e.preventDefault();
tabs.select(getTabAtIndex(currentIndex + 1));
}
function getTabAtIndex(index) {
return tabs.tabGroup.children().eq(index);
}
function tabIndexOfElement(element) {
return tabs.element.find(element).index();
}
function isTabValidAt(tabIndex) {
var el = tabs.contentElement(tabIndex),
val = $(el).kendoValidator().data("kendoValidator");
return val.validate();
}
function onShow(e) {
progress.value(currentIndex + 1);
}
</script>
_registrationStep1.html:
<div>
<div class="form-group">
@Html.LabelFor(m => m.Email)
@(Html.Kendo().TextBoxFor(m => m.Email)
.HtmlAttributes(new { placeholder = "[email protected]", type = "email", @class = "k-textbox required" })
)
</div>
@Html.RadioButtonFor(model => model.Gender, "1", new { id = "male" }) Male
@Html.RadioButtonFor(model => model.Gender, "0", new { id = "female"}) Female
<footer class="col-lg-12 form-group text-right">
@(Html.Kendo().Button()
.Name("Next1")
.Content("Next")
.HtmlAttributes(new { @class = "k-primary" })
.Events(ev => ev.Click("onNextClick")))
</footer>
</div>