Exemple #1
0
        public static SettingDefinition UseTextbox(
            this SettingDefinition settingDefinition,
            Action <TextboxConfiguration> textboxConfigureAction)
        {
            var textboxConfiguration = new TextboxConfiguration(new FieldControlConfigurationDictionary());

            textboxConfigureAction(textboxConfiguration);

            settingDefinition.WithProperty(SettingDefinitionPropertiesNames.ControlConfigurationName, textboxConfiguration.GetConfiguration());
            settingDefinition.WithProperty(SettingDefinitionPropertiesNames.ControlProviderName, TextboxFieldControlProvider.ProviderName);

            return(settingDefinition);
        }
        public override void Validate(FieldControlValidateArgs args)
        {
            var configuration = new TextboxConfiguration(args.FieldDefinition.Configuration);

            if (configuration.Required && (args.Value == null || args.Value.ToString().Length == 0))
            {
                args.ValidationErrors.Add(
                    new System.ComponentModel.DataAnnotations.ValidationResult(
                        L["ValidateValue:Required"],
                        new[] { args.FieldDefinition.Name }
                        ));
            }

            if (args.Value != null && configuration.CharLimit < args.Value.ToString().Length)
            {
                args.ValidationErrors.Add(
                    new System.ComponentModel.DataAnnotations.ValidationResult(
                        L["CharacterCountExceedsLimit", args.FieldDefinition.DisplayName, configuration.CharLimit],
                        new[] { args.FieldDefinition.Name }
                        ));
            }
        }