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
Hi Graeme,
Understanding that the form doesn't have a submit button, but instead uses a click event...will the click event submit the form? The OnSubmit option should trigger however the form gets submitted. You will want to have both OnSubmit and FormSubmit added to the combo and datepicker editors chain.
Take a look at this post as it touches on the similar: http://ko.infragistics.com/community/forums/t/87978.aspx
Please let me know if you need any additional assistance regarding this.
I am still following your post. Please let me know if you need any additional details regarding this.
Great! I will await your update. Thxs.
Hi
Please find a demo project attached.
Run it up and go to the ForceValidation page.
If you click into and out of each field without entering a value you will see validation messages.
Refresh the page.
Now click the Validate button. You will get a validation message on the text editor but not the DatePicker or Combo.
Hopefully it will run up for you - I have removed all of the packages and binaries to keep the file small.
Hello Graeme,
Thank you for your sample. I will be looking further into the behavior you are describing in your sample and will get back to you by the end of the day tomorrow with more information or questions.
Thank you very much for your patience. Please find your project attached with the functionality you were looking to achieve. In order to achieve this functionality, I attached an igValidator to the Name editor and edited the validatorOptions for the igCombo. Please let me know if the behavior you will now see is suitable for your project. Also, please do not hesitate to contact me with more questions.
Is there anything else I can assist you with on the matter? Please do not hesitate to contact me with more questions.