예제 #1
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="viewMode"></param>
        /// <param name="buttons"></param>
        public FormHorizontal(bool viewMode, IList <IHtmlElement> buttons)
            : base(HtmlTag.Form)
        {
            AddClass("form-horizontal");
            Attribute(HtmlAttribute.Method, "post");

            Script    = new Input.ScriptRegister();
            Validator = new FormValidate.FormValidator();
            ViewMode  = viewMode;
            Buttons   = buttons ?? new List <IHtmlElement>();
        }
예제 #2
0
        /// <summary>
        /// 设置输入模式
        /// </summary>
        public override void SetInputMode()
        {
            Tag = HtmlTag.Select;
            Attribute(HtmlAttribute.Name, Name);
            AddClass("form-control");
            Css("width", "100%");
            AddClass("select2");
            if (Values != null)
            {
                Attribute(HtmlAttribute.Multiple, "multiple");
            }
            else if ((PropertyContent.Property.PropertyType.IsGenericType && PropertyContent.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) || PropertyContent.Property.PropertyType == typeof(string))
            {
                if (Value == null || PropertyContent.Required == null)
                {
                    Append(new HtmlElement(HtmlTag.Option).Append(new HtmlRaw("&nbsp;")));
                }
            }
            foreach (var option in Options)
            {
                var item = new HtmlElement(HtmlTag.Option);
                Append(item);
                item.Attribute(HtmlAttribute.Value, option.Value);
                if (Values != null)
                {
                    if (Values.Contains(option.Value))
                    {
                        item.Attribute(HtmlAttribute.Selected, "selected");
                    }
                }
                else
                {
                    if (option.Value == Value)
                    {
                        item.Attribute(HtmlAttribute.Selected, "selected");
                    }
                }
                item.Text(option.Text);
            }
            if (PropertyContent.Disabled || PropertyContent.ReadOnly)
            {
                Attribute(HtmlAttribute.Disabled, "disabled");
            }

            ScriptRegister.Register("Select2Edit", "view.node.find('select.select2').select2();");
        }
예제 #3
0
        /// <summary>
        /// 设置输入模式
        /// </summary>
        public override void SetInputMode()
        {
            Tag = HtmlTag.Div;
            AddClass("tagsinput");
            AddClass("form-control");
            if (PropertyContent.ReadOnly)
            {
                Attribute(HtmlAttribute.ReadOnly, "readonly");
            }
            if (PropertyContent.Disabled)
            {
                Attribute(HtmlAttribute.ReadOnly, "disabled");
            }
            if (WrongValueFormat)
            {
                Text("错误数据类型,请使用字符串列表");
                return;
            }

            foreach (var item in Value)
            {
                if (string.IsNullOrWhiteSpace(item))
                {
                    continue;
                }
                var div = new HtmlElement(HtmlTag.Div);
                div.AppendTo(this);

                var hidden = new HtmlElement(HtmlTag.Input);
                hidden.AppendTo(div);
                hidden.Attribute(HtmlAttribute.Type, "hidden");
                hidden.Attribute(HtmlAttribute.Name, Name);
                hidden.Attribute(HtmlAttribute.Value, item.Trim());

                var span = new HtmlElement(HtmlTag.Span);
                span.AppendTo(div);
                span.Text(item);

                if (!PropertyContent.Disabled && !PropertyContent.ReadOnly)
                {
                    FontAwesome.Times.CreateElement().AddClass("container-parent-remove").AppendTo(span);
                }
            }

            var input = new HtmlElement(HtmlTag.Input);

            if (!PropertyContent.Disabled && !PropertyContent.ReadOnly)
            {
                input.AppendTo(this);
            }
            input.AddClass("input");
            input.Attribute(HtmlAttribute.PlaceHolder, "add tags");
            input.Attribute(HtmlAttribute.Name, Name);
            input.Data("temporary", "temporary");
            input.Data("temporary-for", Name);
            if (InputMaxLength != null)
            {
                input.Attribute(HtmlAttribute.MaxLength, InputMaxLength.Length.ToString());
            }

            ScriptRegister.Register("TagsInputEdit", "oldmansoft.webman.setTagsInput(view, 'div.tagsinput');");
        }