Beispiel #1
0
        /// <summary>
        /// Creates a numeric-text control.
        /// </summary>
        /// <param name="value">Do not pass null.</param>
        /// <param name="allowEmpty"></param>
        /// <param name="setup">The setup object for the numeric-text control.</param>
        /// <param name="minLength"></param>
        /// <param name="maxLength">The maximum number of characters a user can input.</param>
        /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param>
        public NumericTextControl(
            string value, bool allowEmpty, NumericTextControlSetup setup = null, int?minLength = null, int?maxLength = null,
            Action <string, Validator> validationMethod = null)
        {
            setup = setup ?? NumericTextControlSetup.Create();
            (Labeler, PageComponent, Validation) = setup.TextControlSetup.LabelerAndComponentAndValidationGetter(
                value,
                allowEmpty,
                minLength,
                maxLength,
                (postBackValue, validator) => {
                var errorHandler   = new ValidationErrorHandler("value");
                var validatedValue = validator.GetString(errorHandler, postBackValue, allowEmpty, minLength ?? 0, maxLength ?? int.MaxValue);
                if (errorHandler.LastResult != ErrorCondition.NoError)
                {
                    return(null);
                }

                if (!validatedValue.All(char.IsDigit))
                {
                    validator.NoteErrorAndAddMessage("The value must be a number.");
                    return(null);
                }

                return(validatedValue);
            },
                validationMethod);
        }
 /// <summary>
 /// Creates a numeric-text control with the value expressed as a long.
 /// </summary>
 /// <param name="setup">The setup object for the control. Do not pass null.</param>
 /// <param name="validationMethod">A function that validates the value entered by the user and returns a result. Do not pass null.</param>
 public static NavFormControl CreateNumericTextAsLong(NavFormControlSetup setup, Func <long, NavFormControlValidationResult> validationMethod) =>
 new NavFormControl(
     setup,
     validationResultHandler => {
     var val = new DataValue <long>();
     return(val.ToTextControl(
                setup: setup.AutoCompleteResource != null
                                                        ? NumericTextControlSetup.CreateAutoComplete(
                    setup.AutoCompleteResource,
                    placeholder: setup.Placeholder,
                    triggersActionWhenItemSelected: true)
                                                        : NumericTextControlSetup.Create(placeholder: setup.Placeholder),
                value: new SpecifiedValue <long?>(null),
                additionalValidationMethod: validator => validationResultHandler(validationMethod(val.Value), validator)));
 });
 /// <summary>
 /// Creates a numeric-text control with the value expressed as a string.
 /// </summary>
 /// <param name="setup">The setup object for the control. Do not pass null.</param>
 /// <param name="validationMethod">A function that validates the value entered by the user and returns a result. Do not pass null.</param>
 public static NavFormControl CreateNumericTextAsString(NavFormControlSetup setup, Func <string, NavFormControlValidationResult> validationMethod) =>
 new NavFormControl(
     setup,
     validationResultHandler => {
     return(new NumericTextControl(
                "",
                false,
                setup: setup.AutoCompleteResource != null
                                                        ? NumericTextControlSetup.CreateAutoComplete(
                    setup.AutoCompleteResource,
                    placeholder: setup.Placeholder,
                    triggersActionWhenItemSelected: true)
                                                        : NumericTextControlSetup.Create(placeholder: setup.Placeholder),
                validationMethod: (postBackValue, validator) => validationResultHandler(validationMethod(postBackValue), validator)));
 });