Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
Igniteui giCombo & DatePicker - how to force form validation programmatically?
posted

IgniteUI 13.2

I have a c# MVC website which has a view with many IgniteUI elements on it.

Some of those elements are marked as required in the model.

Some of the fields use Editors, some combos and some datepickers.

The form does not use a submit button. I have implemented button click instead(in order to get hierarchical grid in the same view to save in the same DB transaction as the non-grid fields).

I can get the validation failure messages to show for an editor but not for combos or date pickers

So, I have the following for a combo in the view:

@Html.Infragistics().ComboFor(m => m.AccountID).ID("cmbAccount").TextKey("Name").ValueKey("AccountID").InputName("AccountID").ValidatorOptions(o=>o.Required(true).FormSubmit(true).OnChange(true).ShowIcon(true)).DataSource(Model.Accounts).Render()

For DatePicker:

@Html.Infragistics().DatePickerFor(model => model.DateOrderReceived).ReadOnly(blnIsReadOnly).ValidatorOptions(o => o.Required(true)).Render()

For TExtEditor:

@Html.Infragistics().TextEditorFor(model => model.ClientReference).ValidatorOptions().Render()

Model:

[Required(ErrorMessage = "Please select a value.")]
public Int64 ?AccountID { get; set; }

[Required(ErrorMessage = "Please select a value.")]
public DateTime? DateOrderReceived { get; set; }

[Required(ErrorMessage = "Please enter the reference.")]
[StringLength(255, MinimumLength = 3, ErrorMessage="Please enter a value at least 3 characters long.")]
public string ClientReference { get; set; }

And in the button click function in the View:

var bIGFieldsAreValid = true;
var oIsValid= $("#ClientReference").igValidator("validate");
if (oIsValid == 1 || oIsValid == 2) {
bIGFieldsAreValid = false;
}
oIsValid= $("#AccountID").igValidator("validate");
if (oIsValid == 1 || oIsValid == 2) {
bIGFieldsAreValid = false;
}
oIsValid = $("#DateOrderReceived").igValidator().igValidator("validate");
if (oIsValid == 1 || oIsValid == 2) {
bIGFieldsAreValid = false;
}

Only the TextEditor ClientRefrence field gets the validation failure when left empty.

...but if I click into and out of each field the validation messages appear OK, so I only have a problem with programmatically applying the validation to the combo and date picker fields.

I have tried various combinations for the combo and data pickers fields but I can't figure out what I am missing.

What do I need to do to get this to work for combo & data picker fields?

Regards,

Graeme