PDA

View Full Version : [CLOSED] Data annotation validation in form



MTSI
Mar 05, 2013, 10:13 AM
We have the following form which has few input fields created from model with some validations using data annotation. The problem is when we hit on the Save button the validation is not getting fired.



<script>
var saveExhibit = function () {
try {
debugger;
var Url = '@Url.Content("~/Job/Exhibit/ManageExhibit")';
$.ajax({
url: Url,
type: "post",
data: $('form').serialize(),
success: function (result) {
Parent.App.ExhibitWindow.close();
Ext.Msg.hide();
Ext.Msg.alert('Status', result.statusMessage, function () {
debugger;
try {
parent.App.ExhibitWindow.hide();
parent.RefreshExhibitList();
}
catch (e) { }
});
},
error: function (result) {
// debugger;
Ext.Msg.hide();
}
});
} catch (e) {
Ext.Msg.hide();
alert(e.Message);
}
}
</script>

@using (Html.BeginForm("ManageExhibit", "Exhibit", FormMethod.Post, new { id = "ManageExhibit" }))
{
<table width="600px" cellpadding="3" cellspacing="0">
<tr>
<td>
@Html.X().TextFieldFor(model => model.ExhibitNumber, true).LabelAlign(LabelAlign.Top).Width(120).Paddin g(5)
</td>
<td colspan="3">
@Html.X().TextFieldFor(model => model.Description, true).LabelAlign(LabelAlign.Top).Width(410).Paddin g(5)
</td>
</tr>
</table>
@Html.X().Button().ID("SaveButton").Text("Save").I con(Icon.DatabaseSave).Handler("saveExhibit(this); ").Padding(5)
@Html.X().Button().Text("Cancel").Icon(Icon.Cancel ).Handler("cancelWindow();").Padding(5)
}

Daniil
Mar 05, 2013, 12:10 PM
Hi @MTSI,

A validation should not occur on click.

You can validate fields yourself if need using a Field's client side API.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Field-method-validate
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Field-method-isValid

It might be simpler if you used a FormPanel to organize the fields. It has the isValid method which validates all internal fields.

MTSI
Mar 05, 2013, 1:19 PM
Thanks Daniil!
We tried with the formpanel but it was difficult to format the complex forms. Is there a way to format the fields in table format as we do in html?


Hi @MTSI,

A validation should not occur on click.

You can validate fields yourself if need using a Field's client side API.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Field-method-validate
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Field-method-isValid

It might be simpler if you used a FormPanel to organize the fields. It has the isValid method which validates all internal fields.

Daniil
Mar 05, 2013, 2:04 PM
Within a FormPanel you can use any layout including a TableLayout.
http://examples2.ext.net/#/Layout/TableLayout/Simple_in_Markup/

But, personally, I would use a combination of a VBox and an HBox layouts instead of a TableLayout one.