/// <summary> /// Gets the initial value for <paramref name="control"/>. /// </summary> /// <param name="control">The control to get a value for.</param> /// <returns>The initial value for <paramref name="control"/>.</returns> public object GetInitialControlValue(ValueControl control) { IControlWithDefaultValue controlWithDefault = control as IControlWithDefaultValue; if (controlWithDefault != null) { return controlWithDefault.GetDefaultValue() ?? string.Empty; } LikertControl likertControl = control as LikertControl; if (likertControl != null) { return likertControl.Questions.ToDictionary(question => question.Name, question => string.Empty); } return string.Empty; }
/// <summary> /// Verifies a control value. /// </summary> /// <param name="control">The control to verify.</param> /// <param name="modifiedValue">The new value to be verified.</param> /// <param name="existingValue">The previous value.</param> /// <param name="controlAccess">The control access.</param> /// <returns>The sanitised control value.</returns> private object VerifyValueControl(ValueControl control, object modifiedValue, object existingValue, ControlAccess controlAccess) { if (controlAccess.AccessLevel != AccessLevel.Write) { return existingValue ?? this.appInitialiser.GetInitialControlValue(control); } return modifiedValue; }
/// <summary> /// Creates a <see cref="Microsoft.Practices.EnterpriseLibrary.Validation.Validator"/> that will validate /// a mandatory field. /// </summary> /// <param name="control">The control to create a validator for.</param> /// <returns>A <see cref="Microsoft.Practices.EnterpriseLibrary.Validation.Validator"/> that will validate /// a mandatory field.</returns> private Validator CreateValidatorForMandatory(ValueControl control) { IControlWithOptions controlWithOptions = control as IControlWithOptions; if (controlWithOptions != null && controlWithOptions.AllowMultipleSelect) { return new ArrayLengthValidator(1, int.MaxValue) { MessageTemplate = string.IsNullOrWhiteSpace(control.MandatoryMessage) ? ValidationMessage.MandatoryCheckboxGroup : control.MandatoryMessage }; } return new EntLib.StringLengthValidator(0, true) { MessageTemplate = string.IsNullOrWhiteSpace(control.MandatoryMessage) ? ValidationMessage.Mandatory : control.MandatoryMessage }; }