Hello,
I have the following situation:
I have a grid with two DateTime columns (startDate and endDate), when adding/editing I would like to disable the Done button if the startDate is after the endDate. Something like (pseudocode):
if (endDate >startDate) doneButton.disable()
Is this possible? What is the preferred way to check condition about several columns. I am writing all my code in C# over MVC.net.
Thanks in advance
Please share a real example where I can get the data from 2 different cells in the same row and compare both and then return the validation as either true or false, always returning a false will end up not allowing user to let the grid have user input.
Hello Javier,
I have created a sample to demonstrate this matter for you. Note that I have removed the JavaScirpt, CSS and dll Infragistics files for file size to be able to attach to the forums. So you will want to replace them before running. As you note you will want to use v16.1 as that will give you access to the Custom method. Looking are your code it appears correct. You can set the error message through Custom or by setting ErrorMessage as you can see I have commented out. I use the DatePicker editor, I also tested with the regular date editor and it works as well. Let me know what you see when you run my sample. If you are still having an issue with your afterwards please attach it to this forum thread so I can look further into this matter to see why this behavior isn’t working for you.
Hello again,
Let me update the situation given the progress I have made.
I have updated Infragistics to the 2016.1 version and now the Custom method does appear as available. I have written the following code:
.ColumnSettings(c => { c.ColumnSetting().ColumnKey("StartDate").Required(true).Validation(true) .DateEditorOptions(o => { o.ValidatorOptions(vo => vo.Custom("checkDates", "Error in dates")); }); c.ColumnSetting().ColumnKey("EndDate").Required(true).Validation(true) .DateEditorOptions(o => { o.ValidatorOptions(vo => vo.Custom("checkDates", "Error in dates")); }); })
function checkDates(value, fieldOptions) { return false; }
In this code I define two ColumnSettings for each of the dates and I am setting the validation options with the custom callback to use the checkDates javascript function. I have added the string error in the custom to see the text.
This does not work. I have put a breakpoint the javascript code on the browser and it is never called. Also, the error string "Error in dates" is not shown either.
What am I missing? Is there a problem with the definition of the javascript function?
Hello Mike,
I have tried the C# code you posted. It does not compile because there is no Custom method in the Validator Options. The only method that is similar (and obviously is not the one I need) is CustomErrorMessage(String).
Let me show you what I wrote:
c.ColumnSetting().ColumnKey("StartHour").Required(true).DateEditorOptions(o => o.ValidatorOptions(vo => vo.Custom("checkDates")));
This code does not compile. Why the method Custom is not available? Am I missing a reference or something? What version of Infragistics do I need?
Thank you for the update. You would want to apply the validation options on the editor/cell/column you want to validate. Since you are using MVC you would want to do it something like the following:
features.Updating().ColumnSettings(cs => cs.ColumnSetting().ColumnKey("Date").DateEditorOptions(options => options.ValidatorOptions(vo => vo.Custom("customMethod"))) );
Where “customMethod” is your function/method where you validate the date:
http://www.igniteui.com/help/api/2016.1/ui.igvalidator#options:custom
function customMethod(value, fieldOptions) {//Todo validate data}