Пример #1
0
        private void CreateInput(FormHorizontal form, Type type, object model, List <string> parents)
        {
            foreach (var item in Util.ModelProvider.Instance.GetItems(type))
            {
                var parentsAndCurrent = new List <string>();
                parentsAndCurrent.AddRange(parents);
                parentsAndCurrent.Add(item.Name);
                if (item.Expansion)
                {
                    CreateInput(form, item.Property.PropertyType, model == null ? null : item.Property.GetValue(model), parentsAndCurrent);
                    continue;
                }
                var name    = string.Join(".", parentsAndCurrent);
                var content = Items[item.Property];
                var value   = model == null ? null : content.Property.GetValue(model);
                if (content.Hidden)
                {
                    var hidden = new FormInputCreator.Inputs.Hidden();
                    hidden.Init(content, name, value ?? string.Empty, null);
                    hidden.SetInputMode();
                    hidden.AppendTo(form);
                    continue;
                }

                var parameter = new FormInputCreator.HandlerParameter(content, name, value, Source, form.Script, form.Validator, content.Attributes.Get <Annotations.HtmlDataAttribute>());
                var input     = FormInputCreator.InputCreator.Instance.Handle(parameter);
                if (InputMode)
                {
                    input.SetInputMode();
                }
                else
                {
                    input.SetViewMode();
                }
                form.Add(content.Display, input.CreateGrid(Column.Sm9 | Column.Md10));
                content.SetValidate(form.Validator, name);
            }
        }
Пример #2
0
        /// <summary>
        /// 创建表单
        /// </summary>
        /// <returns></returns>
        public FormHorizontal Create()
        {
            if (InputMode)
            {
                if (SubmitButton != null)
                {
                    Buttons.Insert(0, SubmitButton);
                }
                if (ResetButton != null)
                {
                    Buttons.Insert(0, ResetButton);
                }
            }
            var form = new FormHorizontal(!InputMode, Buttons);

            if (Action != null)
            {
                form.Attribute(HtmlAttribute.Action, Action.Path);
                Action.Behave.SetTargetAttribute(form);
            }
            CreateInput(form, typeof(TModel), Model, new List <string>());
            return(form);
        }