Hello,
I have a problem and I have no idea how to solve it.
My task:
Alternate Weeks field is required and its value must be bigger than 0. No problem here – my custom validator works fine and proper messages can be displayed.
Alternate Week Start Date field should be required only if Alternate Weeks value is bigger than 1.
My solution (which does not work as intended):
Logic: When a new row starts to be edited I register two validators – one for Alternate Weeks and one for Alternate Weeks Start Date. When I make some change in Alternate Weeks field I manually call validation on Alternate Weeks Start Date field.
Code:
// Columns settings (other grid settings is not important IMHO)
feature.Updating().Validation(true).EnableAddRow(true).EnableDeleteRow(true).EnableDataDirtyException(true).AddRowLabel(Resources.Translations.addRoute).ColumnSettings(cs =>
{
cs.ColumnSetting().ColumnKey("RouteId").Required(true).EditorType(ColumnEditorType.Combo).ComboEditorOptions(co => co.DataSource(ViewBag.AvailableRoutes).ValueKey("Id").TextKey("Name").Mode(Infragistics.Web.Mvc.ComboMode.DropDown).EnableClearButton(false));
cs.ColumnSetting().ColumnKey("AlternateWeeks").Required(true).TextEditorOptions(o => o.ValidatorOptions(options => options.OnBlur(true)));
cs.ColumnSetting().ColumnKey("AlternateWeeksStartDate").Required(false).TextEditorOptions(o => o.ValidatorOptions(options => options.OnBlur(true)));
});
$("#gridRouteAddresses").on("iggridupdatingeditrowstarted", function (evt, ui) {
// Find Alternate Weeks field and assign default value of 1
var alternateWeeks = $("#gridRouteAddresses").igGridUpdating("editorForKey", "AlternateWeeks");
$(alternateWeeks).igEditor("text", "1");
alternateWeeksValidator(validateAlternateWeeks);
alterWeeksStartDateValidator(validateAlternateWeeksStartDate);
return true;
function alternateWeeksValidator(validateFunction) {
var fieldValue = $("#gridRouteAddresses").igGridUpdating("editorForKey", "AlternateWeeks");
(function (fieldValue) {
var _fieldValue = fieldValue;
var _fieldValueValidator = _fieldValue.validator();
_fieldValueValidator._setOption("checkValue", function (evt, ui) {
var args = { fieldValue: _fieldValue.value(), message: "" };
var isValid = validateFunction(args);
if (!isValid) {
ui.message = args.message;
return false;
}
})(fieldValue.data("igEditor"));
function alterWeeksStartDateValidator(validateFunction) {
var dateField = $("#gridRouteAddresses").igGridUpdating("editorForKey", "AlternateWeeksStartDate");
(function (dateField, fieldValue) {
var _dateField = dateField;
var _dateFieldValidator = _dateField.validator();
_dateFieldValidator._setOption("checkValue", function (evt, ui) {
var args = { fieldValue: _fieldValue.value(), dateField: _dateField.value(), message: "" };
})(dateField.data("igEditor"), fieldValue.data("igEditor"));
function validateAlternateWeeks(e) {
var fieldValue = e.fieldValue;
if (fieldValue == null) {
e.message = 'Alternate Weeks field is required.';
if (fieldValue < 1) {
e.message = 'Alternate Weeks value must be positive number bigger then 0.';
return $(dateField).igEditor("validate");
function validateAlternateWeeksStartDate(e) {
var dateValuee = e.dateField;
if (fieldValue > 1 && dateValuee == null) {
e.message = 'Alternate weeks start date is required.';
Problems:
I can change the value of Alternate Weeks to any value I want and Alternate Weeks Start Date validator is called. Once I change the value of Alternate Weeks to something bigger than 1 error message pops-up and “Done” button becomes disabled (correct behavior). Problem is that when I change it back to the value of 1 – validator on Alternate Weeks Start Date field can never be called again ($(dateField).igEditor("validate"); is always false).
Second problem is that if change the value of Alternate Weeks to 1 (valid value), enter and leave Alternate Weeks Start Date field, validation is called again and error message disappears but “Done” button remains disabled.
Please, help me. What am I doing wrong?
Hello Adam Kopriva,
I have created a support case for you with an ID of CAS-158469-L0D1H8. The matter has been determined to be a development issue and has been logged in our tracking system with ID: 203012.
I will leave this case open and update you with any new information. You can view the status of the development issue connected to this case by going to the “Account” tab on our website, selecting "My Support Activity" and then this support case will be listed there. Then, you may select the "Development Issues" tab to view details of this development issue.
During my research, I found a workaround where you can call the dateField validator directly instead calling validate on the editor. In your validateAlternateWeeks() function, you can return the following:
return dateField.data("igEditor").validator().validate();
Please let me know if you have any questions.