public override void Validating(ValidatingContext context) { if (context.FormName == "ListLayout") { if (context.ValueProvider.GetValue("Order") == null) { context.ModelState.AddModelError("Order", T("You must provide an Order").Text); } } }
public void Validating(ValidatingContext context) { if (context.FormName == "ActionDecision") { if (context.ValueProvider.GetValue("Script").AttemptedValue == string.Empty) { context.ModelState.AddModelError("Script", T("You must provide a Script").Text); } } }
public override void Validating(ValidatingContext context) { if (context.FormName == SortCriterionFormProvider.FormName) { if (context.ValueProvider.GetValue("Sort") == null) { context.ModelState.AddModelError("Sort", T("The Sort field is required.").Text); } } }
public override void Validating(ValidatingContext context) { if (context.FormName == "ActivityTimer") { if (context.ValueProvider.GetValue("Amount").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Amount", T("You must provide an Amount").Text); } if (context.ValueProvider.GetValue("Unity").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Unity", T("You must provide a Type").Text); } } }
void IFormEventHandler.Validating(ValidatingContext context) { if (context.FormName != "VerifyUserUnicity") return; var userName = context.ValueProvider.GetValue("UserName").AttemptedValue; var email = context.ValueProvider.GetValue("Email").AttemptedValue; if (String.IsNullOrWhiteSpace(userName)) { context.ModelState.AddModelError("UserName", T("You must specify a username or a token that evaluates to a username.").Text); } if (String.IsNullOrWhiteSpace(email)) { context.ModelState.AddModelError("Email", T("You must specify an email address or a token that evaluates to an email address.").Text); } }
void IFormEventHandler.Validating(ValidatingContext context) { if (context.FormName != "SignInUser") return; var userName = context.ValueProvider.GetValue("UserNameOrEmail").AttemptedValue; var password = context.ValueProvider.GetValue("Password").AttemptedValue; if (String.IsNullOrWhiteSpace(userName)) { context.ModelState.AddModelError("UserNameOrEmail", T("You must specify a user name, email address or a token that evaluates to a username or email address.").Text); } if (String.IsNullOrWhiteSpace(password)) { context.ModelState.AddModelError("Password", T("You must specify a password or a token that evaluates to a password.").Text); } }
public override void Validating(ValidatingContext context) { if (context.FormName == "ActionDelay") { if (context.ValueProdiver.GetValue("Amount").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Amount", T("You must provide an Amount").Text); } if (context.ValueProdiver.GetValue("Unity").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Unity", T("You must provide a Type").Text); } if (context.ValueProdiver.GetValue("RuleId").AttemptedValue == String.Empty) { context.ModelState.AddModelError("RuleId", T("You must select at least one Rule").Text); } } }
public override void Validating(ValidatingContext context) { if (context.FormName == "GridLayout") { if (context.ValueProvider.GetValue("Alignment") == null) { context.ModelState.AddModelError("Alignment", T("The field Alignment is required.").Text); } if (context.ValueProvider.GetValue("Columns") == null) { context.ModelState.AddModelError("Columns", T("The field Columns/Lines is required.").Text); } else { int value; if (!Int32.TryParse(context.ValueProvider.GetValue("Columns").AttemptedValue, out value)) { context.ModelState.AddModelError("Columns", T("The field Columns/Lines must be a valid number.").Text); } } } }
public override void Validating(ValidatingContext context) { if (context.FormName == NumericFilterForm.FormName) { var isRange = new[] { "Between", "NotBetween" }.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue); var min = context.ValueProvider.GetValue("Min"); var max = context.ValueProvider.GetValue("Max"); var value = context.ValueProvider.GetValue("Value"); // validating mandatory values if (isRange) { if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text); } if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text); } } else { if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text); } } if (!context.ModelState.IsValid) { return; } decimal output; if (isRange) { if (!Decimal.TryParse(min.AttemptedValue, out output) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} should contain a valid number", T("Min").Text).Text); } if (!Decimal.TryParse(max.AttemptedValue, out output) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} should contain a valid number", T("Max").Text).Text); } } else { if (!Decimal.TryParse(value.AttemptedValue, out output) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} should contain a valid number", T("Value").Text).Text); } } } }
public void Validating(ValidatingContext context) { if (context.FormName != "EmailActivity") return; var recipients = context.ValueProvider.GetValue("Recipients").AttemptedValue; var subject = context.ValueProvider.GetValue("Subject").AttemptedValue; var body = context.ValueProvider.GetValue("Body").AttemptedValue; if (String.IsNullOrWhiteSpace(recipients)) { context.ModelState.AddModelError("Recipients", T("You must specify at least one recipient.").Text); } if (String.IsNullOrWhiteSpace(subject)) { context.ModelState.AddModelError("Subject", T("You must provide a Subject.").Text); } if (String.IsNullOrWhiteSpace(body)) { context.ModelState.AddModelError("Body", T("You must provide a Body.").Text); } }
public void Validating(ValidatingContext context) { if (context.FormName == "ActionEmail") { if (context.ValueProvider.GetValue("Recipient").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text); } if (context.ValueProvider.GetValue("Subject").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text); } if (context.ValueProvider.GetValue("Body").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Body", T("You must provide a Body").Text); } if (context.ValueProvider.GetValue("RecipientOther").AttemptedValue == String.Empty && context.ValueProvider.GetValue("Recipient").AttemptedValue == "other") { context.ModelState.AddModelError("Recipient", T("You must provide an e-mail address").Text); } } }
public void Validated(ValidatingContext context) { }
void IFormEventHandler.Validated(ValidatingContext context) {}
public override void Validating(ValidatingContext context) { if (context.FormName == DateTimeFilterForm.FormName) { var isRange = new[] {"Between", "NotBetween"}.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue); var min = context.ValueProvider.GetValue("Min"); var max = context.ValueProvider.GetValue("Max"); var value = context.ValueProvider.GetValue("Value"); var valueType = context.ValueProvider.GetValue("ValueType"); // validating mandatory values if (isRange) { if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text); } if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text); } } else { if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text); } } if (!context.ModelState.IsValid) { return; } // validating data type if (valueType.AttemptedValue == "0") { // A date if(isRange) { if(!_dateRegEx.IsMatch(min.AttemptedValue) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Min").Text).Text); } if (!_dateRegEx.IsMatch(max.AttemptedValue) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Max").Text).Text); } } else { if (!_dateRegEx.IsMatch(value.AttemptedValue) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Value").Text).Text); } } } else { // An offset int number; if (isRange) { if (!Int32.TryParse(min.AttemptedValue, out number) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} must be a valid number.", T("Min").Text).Text); } if (!Int32.TryParse(max.AttemptedValue, out number) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} must be a valid number.", T("Max").Text).Text); } } else { if (!Int32.TryParse(value.AttemptedValue, out number) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} must be a valid number.", T("Value").Text).Text); } } } } }
public void Validate(ValidatingContext context) { _formEventHandlers.Invoke(dispatch => dispatch.Validating(context), Logger); _formEventHandlers.Invoke(dispatch => dispatch.Validated(context), Logger); }
public void Validated(OrchardForms.ValidatingContext context) { }
public void Validating(OrchardForms.ValidatingContext context) { if (context.FormName != DateTimeFilterForm.FormName) { return; } var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(context.ValueProvider.GetValue("Operator").AttemptedValue)); string dateFrom = context.ValueProvider.GetValue("DateFrom").AttemptedValue; string timeFrom = context.ValueProvider.GetValue("TimeFrom").AttemptedValue; string dateTo = context.ValueProvider.GetValue("DateTo").AttemptedValue; string timeTo = context.ValueProvider.GetValue("TimeTo").AttemptedValue; var cultureFrom = CultureInfo.GetCultureInfo(context.ValueProvider.GetValue("CultureFrom").AttemptedValue); var cultureTo = CultureInfo.GetCultureInfo(context.ValueProvider.GetValue("CultureTo").AttemptedValue); var utcNow = DateTime.UtcNow; DateTime from = _dateLocalizationServices.ConvertToSiteTimeZone(utcNow); DateTime to = _dateLocalizationServices.ConvertToSiteTimeZone(utcNow); switch (op) { case DateTimeOperator.Between: bool parseOk = true; try { from = Convert.ToDateTime(dateFrom + " " + timeFrom, cultureFrom); } catch { context.ModelState.AddModelError("DateFrom", T("Invalid dates and times").Text); parseOk = false; } try { to = Convert.ToDateTime(dateTo + " " + timeTo, cultureTo); } catch { context.ModelState.AddModelError("DateTo", T("Invalid dates and times").Text); parseOk = false; } if (parseOk && from > to) { context.ModelState.AddModelError("DateFrom", T("First date must be before second date").Text); } break; case DateTimeOperator.LessThan: try { to = Convert.ToDateTime(dateTo + " " + timeTo, cultureTo); } catch { context.ModelState.AddModelError("DateTo", T("Invalid dates and times").Text); } break; case DateTimeOperator.GreaterThan: try { from = Convert.ToDateTime(dateFrom + " " + timeFrom, cultureFrom); } catch { context.ModelState.AddModelError("DateFrom", T("Invalid dates and times").Text); } break; default: context.ModelState.AddModelError("Operator", T("Invalid operator").Text); break; } }
public virtual void Validated(ValidatingContext context) { }
public virtual void Validated(ValidatingContext context) {}
public void Validate(ValidatingContext context) { _formEventHandlers.Invoke(dispatch => dispatch.Validating(context), Logger); _formEventHandlers.Invoke(dispatch => dispatch.Validated(context), Logger); }