<div class="editor-label"> @Html.Label((ViewData.ModelMetadata.DisplayName??ViewData.ModelMetadata.PropertyName), new Dictionary<string, object> { { "for", ViewData.ModelMetadata.PropertyName } }) </div> <div class="editor-field"> @if (ViewData.ModelMetadata.ModelType.IsNumeric()) { @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { type = "number", @class = "numericOnly" }) } else { @Html.TextBox("", (object)Model, new Dictionary<string, object> { { "id", ViewData.ModelMetadata.PropertyName }, { "name", ViewData.ModelMetadata.PropertyName }, { "class", "text-box single-line"}, { "data-bind", "value: " + ViewData.ModelMetadata.PropertyName }, }) } @Html.ValidationMessage(ViewData.ModelMetadata.PropertyName, new Dictionary<string, object> { { "data-valmsg-for", ViewData.ModelMetadata.PropertyName } }) </div>where numericOnly class is
$(".numericOnly").keypress(function (e) { if (String.fromCharCode(e.keyCode).match(/[^0-9]/g)) return false; });and I added this Remote attribute today
namespace CardNumbers.Models { public class ClientViewModel { public Client Client { get; set; } [Required] [DisplayName("Client No")] [UIHint("Number")] [Column("client_no", TypeName = "smallint")] [Remote("doesClientNoExist", "Client", HttpMethod = "POST", ErrorMessage = "Client Number already exists. Please enter a different Client Number.")] public virtual Int16 Number { get; set; } [Required] [Column("client_name", TypeName = "varchar")] [DisplayName("Client Name")] [MaxLength(30, ErrorMessage = "Client Name should not be longer than 30 characters")] [MinLength(3, ErrorMessage = "Client Name is too short")] [Remote("doesClientNameExist", "Client", HttpMethod = "POST", ErrorMessage = "Client Name already exists. Please enter a different Client Name.")] public virtual string Name { get; set; } public int id { get; set; } } }So, now, after I open the Add dialog and type the first digit, the doesClientNoExist method fire. I want to be able to complete the input before firing the validations. I seem to have the similar problem with phone or email - the validation messages show right away after I start typing.