Пример #1
0
        /// <summary>
        /// Creates the control main element.
        /// </summary>
        /// <returns>The control IFWHtmlElement interface.</returns>
        protected override IFWHtmlElement CreateControl()
        {
            var input = new FWInputElement(Name, FWInputType.Hidden);

            input.MergeAttributes(Attributes);
            if (!string.IsNullOrWhiteSpace(CustomCss))
            {
                input.AddCssClass(CustomCss);
            }

            input.Id       = Id;
            input.DataType = "fw-hidden";

            if (DataBind)
            {
                DataBind.AddMainBind(FWBindConfiguration.VALUE);
                input.DataBind = DataBind.CreateBind();
            }
            else if (Model != null)
            {
                input.Value = Model.ToString();
            }
            else if (FWReflectionHelper.IsNumeric(ModelType))
            {
                // If the property is a number, but the model is null, the value defaults to 0.
                input.Value = "0";
            }

            return(input);
        }
Пример #2
0
        /// <summary>
        /// Creates a new Textbox control.
        /// </summary>
        /// <param name="requestContext">The request helper.</param>
        /// <param name="model">The current model.</param>
        /// <param name="metadata">The model metadata.</param>
        public FWTextboxControl(FWRequestContext requestContext, object model, ModelMetadata metadata)
            : base(requestContext, model, metadata)
        {
            if (metadata.AdditionalValues.ContainsKey(nameof(FWMaskAttribute)))
            {
                var mask = (metadata.AdditionalValues[nameof(FWMaskAttribute)] as FWMaskAttribute);
                _mask        = mask.Mask;
                _reversemask = mask.Reverse;
            }

            if (_regexPattern == null)
            {
                if (FWReflectionHelper.IsNumeric(ModelType))
                {
                    _regexPattern = (FWReflectionHelper.IsIntegral(ModelType)) ? @"^\d+$" : $@"^[0-9]\d*(\{CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator}\d*)?$";
                }
            }
        }