Example #1
0
 internal HtmlFormControl(HtmlForm form, HtmlObject element, string name, HtmlControlType controlType, HtmlInputType inputType)
 {
     Form        = form;
     Element     = element;
     Name        = name;
     ControlType = controlType;
     InputType   = inputType;
 }
Example #2
0
 protected BaseSecuredControl(HtmlTextWriterTag Tag, HtmlInputType InputType)
     : base(Tag)
 {
     m_Text                   = "";
     m_Description            = "";
     m_SecurityContext        = "";
     m_bCausesValidation      = false;
     m_bRequiresAuthorization = false;
     m_bDoPostBack            = false;
 }
        public static IHtmlContent ToInput(this RouteValueDictionary htmlAttributes, HtmlInputType inputType, string value)
        {
            var input = new TagBuilder(HtmlTag.Input.ToStringLower());

            input.MergeAttribute(HtmlAttribute.Type.ToLocalization().ToLower(), inputType.ToStringLower());
            if (!string.IsNullOrWhiteSpace(value))
            {
                input.MergeAttribute(HtmlAttribute.Value.ToStringLower(), value);
            }

            input.MergeAttributes(htmlAttributes, true);
            input.TagRenderMode = TagRenderMode.SelfClosing;
            return(input);
        }
Example #4
0
        public static HtmlTag CreateInputElementFor <TModel, TR>(HtmlHelpers <TModel> html,
                                                                 Expression <Func <TModel, TR> > prop, HtmlInputType inputType, object htmlAttributes) where TModel : class
        {
            var propertyInfo = prop.AsPropertyInfo();

            if (propertyInfo == null)
            {
                return(null);
            }
            var name = propertyInfo.Name;

            var tag = new HtmlTag("input").
                      WithAttribute("type", inputType.ToString().ToLowerInvariant()).
                      WithAttribute("name", name.ToLowerInvariant());

            if (inputType != HtmlInputType.Password)
            {
                tag.ApplyModelProperty(html.Model, propertyInfo.Name);
            }


            tag.WithAttributes(htmlAttributes);

            return(tag);
        }
Example #5
0
 public InputHelper(HtmlInputType htmlInputType)
 {
     inputType = htmlInputType;
 }
Example #6
0
 public InputHelper(HtmlInputType htmlInputType)
 {
     inputType = htmlInputType;
 }
        public IDictionary <string, object> GetHtmlAttributes(HtmlInputType inputType)
        {
            var htmlAttributes = base.GetHtmlAttributes();

            if (string.IsNullOrEmpty(this.DataType) == false)
            {
                htmlAttributes.Add("data-type", this.DataType);
            }

            if (string.IsNullOrEmpty(this.Style) == false)
            {
                htmlAttributes.Add("data-locale", this.DataLocale);
            }

            if (inputType == HtmlInputType.Text ||
                inputType == HtmlInputType.Email ||
                inputType == HtmlInputType.Search ||
                inputType == HtmlInputType.Password ||
                inputType == HtmlInputType.Tel ||
                inputType == HtmlInputType.Url)
            {
                if (this.MinLength.HasValue)
                {
                    htmlAttributes.Add("minlength", this.MinLength.Value.ToString(NumberFormatInfo.InvariantInfo));
                }

                if (this.MaxLength.HasValue)
                {
                    htmlAttributes.Add("maxlength", this.MaxLength.Value.ToString(NumberFormatInfo.InvariantInfo));
                }
            }

            if (inputType == HtmlInputType.Number)
            {
                if (this.Min.HasValue)
                {
                    htmlAttributes.Add("min", this.Min.Value.ToString(NumberFormatInfo.InvariantInfo));
                }

                if (this.Max.HasValue)
                {
                    htmlAttributes.Add("max", this.Max.Value.ToString(NumberFormatInfo.InvariantInfo));
                }
            }

            if (this.IsReadonly.HasValue && this.IsReadonly.Value)
            {
                htmlAttributes.Add("readonly", "true");
            }

            if (this.IsHidden.HasValue && this.IsHidden.Value)
            {
                inputType = HtmlInputType.Hidden;
            }

            switch (inputType)
            {
            case HtmlInputType.CheckBox:
                htmlAttributes.Add("type", "checkbox");
                break;

            case HtmlInputType.Number:
                htmlAttributes.Add("type", "number");
                break;

            case HtmlInputType.Text:
                htmlAttributes.Add("type", "text");
                break;

            case HtmlInputType.Email:
                htmlAttributes.Add("type", "email");
                break;

            case HtmlInputType.Search:
                htmlAttributes.Add("type", "search");
                break;

            case HtmlInputType.Password:
                htmlAttributes.Add("type", "password");
                break;

            case HtmlInputType.Tel:
                htmlAttributes.Add("type", "tel");
                break;

            case HtmlInputType.Url:
                htmlAttributes.Add("type", "url");
                break;

            case HtmlInputType.Hidden:
                htmlAttributes.Add("type", "hidden");
                break;

            default:
                throw new ArgumentException("Unknown enum type: " + inputType);
            }

            if (string.IsNullOrEmpty(this.Placeholder) == false)
            {
                htmlAttributes.Add("placeholder ", this.Placeholder);
            }

            return(htmlAttributes);
        }