コード例 #1
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();");
        }
コード例 #2
0
ファイル: TagsInput.cs プロジェクト: Oldmansoft/WebMan
        /// <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');");
        }