示例#1
0
        public static IHtmlString UploadFor(this KenticoForm html, IForm model, string controlName, IControlRenderer customRenderer)
        {
            var control         = model.Controls.FirstOrDefault(ctrl => ctrl.Name.Equals(controlName, StringComparison.OrdinalIgnoreCase));
            var renderedControl = customRenderer.Render(control);

            return(MvcHtmlString.Create(renderedControl));
        }
示例#2
0
        public static IHtmlString TextBoxFor(this KenticoForm html, IControl control, IControlRenderer customRenderer)

        {
            var renderedControl = customRenderer.Render(control);

            return(MvcHtmlString.Create(renderedControl));
        }
示例#3
0
        public static IHtmlString UploadFor(this KenticoForm html, IForm model, string controlName, object htmlAttributes)
        {
            var renderer = ControlRendererRegistrar.Resolve(ControlType.UploadFile);
            var control  = model.Controls.FirstOrDefault(ctrl => ctrl.Name.Equals(controlName, StringComparison.OrdinalIgnoreCase));

            return(MvcHtmlString.Create(renderer.Render(control, htmlAttributes)));
        }
        public static IHtmlString BeginForm(this KenticoForm html, string action, string controllerName, string formName, string classes, ISubmissionOptions options, string method, string dataLayout, bool validate, bool summary)
        {
            var submitData = "data-submit-";

            if (!string.IsNullOrEmpty(options.RedirectUrl))
            {
                submitData += $"url=\"{options.RedirectUrl}\" ";
            }
            if (!string.IsNullOrEmpty(options.DisplayText))
            {
                submitData += $"text=\"{options.DisplayText}\" ";
            }
            if (options.ClearAfterSave)
            {
                submitData += $"reset=\"{options.ClearAfterSave}\" ";
            }

            return(MvcHtmlString.Create($"<form action=\"/{controllerName}/{action}\" " +
                                        "entype=\"multipart/form-data\" " +
                                        $"method=\"{method}\" " +
                                        $"class=\"form form--kentico {classes}\" " +
                                        submitData +
                                        $"{(validate ? " data-validate" : string.Empty)}{(summary ? " " + "data-summary" : string.Empty)} " +
                                        $"data-layout=\"{dataLayout}\">" +
                                        $"<input type=\"hidden\" name=\"formname\" value=\"{formName}\" /> "));
        }
        public static IHtmlString ListBoxFor <TControl>(this KenticoForm html, TControl control, IControlRenderer customRenderer) where TControl : IControl

        {
            var renderedControl = customRenderer.Render(control);

            return(MvcHtmlString.Create(renderedControl.ToString()));
        }
示例#6
0
        public static IHtmlString UploadFor(this KenticoForm html, IForm model, string controlName)
        {
            var control = model.Controls.FirstOrDefault(ctrl => ctrl.Name.Equals(controlName, StringComparison.OrdinalIgnoreCase));

            return(control != null?
                   CalendarFor(html, control, ControlRendererRegistrar.Resolve(ControlType.UploadFile))
                       : MvcHtmlString.Create(""));
        }
        public static IHtmlString SubmitButton(this KenticoForm html, string submitText, object htmlAttributes)
        {
            var tag = new MultiLevelTag("button");

            tag.Attributes.Add("type", "submit");
            tag.Attributes.Add("data-submit", null);
            tag.SetInnerText(submitText);

            if (htmlAttributes != null)
            {
                var customAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
                if (customAttributes != null)
                {
                    foreach (var item in customAttributes.Where(item => !tag.Attributes.ContainsKey(item.Key)))
                    {
                        tag.Attributes.Add(item.Key, item.Value.ToString());
                    }
                }
            }

            tag.AddCssClass("button");

            return(MvcHtmlString.Create(tag.ToString()));
        }
 public static IHtmlString EndForm(this KenticoForm html)
 {
     return(MvcHtmlString.Create("</form>"));
 }
示例#9
0
        public static IHtmlString EditorFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl

        {
            return(EditorFor <TControl>(html, control, ControlRendererRegistrar.Resolve(ControlType.HtmlArea)));
        }
        public static IHtmlString ListBoxFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl

        {
            return(ListBoxFor <TControl>(html, control, ControlRendererRegistrar.Resolve(ControlType.ListBox)));
        }
示例#11
0
        public static IHtmlString MultipleChoiceFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl

        {
            return(MultipleChoiceFor <TControl>(html, control, ControlRendererRegistrar.Resolve(ControlType.MultipleChoice)));
        }
        /// <summary>
        /// Convenience method to render a set of form fields complete with a containing label
        /// </summary>
        /// <typeparam name="TControls"></typeparam>
        /// <param name="model"></param>
        /// <param name="controls"></param>
        /// <returns></returns>
        public static IHtmlString RenderFormControls <TControls>(this KenticoForm model, TControls controls) where TControls : IList <IControl>
        {
            var result = new StringBuilder();

            foreach (var control in controls)
            {
                switch (control.Type)
                {
                case ControlType.Calendar:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.CalendarFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.CheckBox:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.CheckboxFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.DropDownList:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.DropDownListFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.Country:
                    throw new NotImplementedException("Not done yet");

                case ControlType.Email:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.EmailFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.Label:
                    result.AppendLine(model.LabelFor(control).ToHtmlString());
                    break;

                case ControlType.ListBox:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.ListBoxFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.MultipleChoice:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.MultipleChoiceFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.RadioButton:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.RadioButtonFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.TextBox:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.TextBoxFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.TextArea:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.TextAreaFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.UploadFile:
                    result.AppendLine(string.Concat("<div class=\"form-row\">", model.LabelFor(control).ToHtmlString(), model.UploadFor(control).ToHtmlString(), "</div>"));
                    break;

                case ControlType.Unknown:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(MvcHtmlString.Create(result.ToString()));
        }
示例#13
0
        public static IHtmlString DropDownListFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl

        {
            return(DropDownListFor(html, control, ControlRendererRegistrar.Resolve(ControlType.DropDownList)));
        }
 public static IHtmlString SubmitButton(this KenticoForm html, string submitText)
 {
     return(html.SubmitButton(submitText, null));
 }
示例#15
0
        public static IHtmlString EmailFor <TControl>(this KenticoForm html, TControl control, IControlRenderer renderer) where TControl : IControl
        {
            var renderedControl = renderer.Render(control);

            return(MvcHtmlString.Create(renderedControl));
        }
 public static IHtmlString CalendarFor(this KenticoForm html, IControl control)
 {
     return(CalendarFor(html, control, ControlRendererRegistrar.Resolve(ControlType.Calendar)));
 }
示例#17
0
        public static IHtmlString RadioButtonFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl

        {
            return(RadioButtonFor <TControl>(html, control, ControlRendererRegistrar.Resolve(ControlType.RadioButton)));
        }
示例#18
0
 public static IHtmlString BeginForm(this KenticoForm html, string action, string controllerName, string formName, string classes, ISubmissionOptions options, string method, string dataLayout, bool validate)
 {
     return(BeginForm(html, action, controllerName, formName, classes, options, method, dataLayout, validate, false));
 }
示例#19
0
 public static IHtmlString BeginForm(this KenticoForm html, string action, string controllerName, string formName, string classes, ISubmissionOptions options, string dataLayout)
 {
     return(BeginForm(html, action, controllerName, formName, classes, options, "post", dataLayout, true, false));
 }
示例#20
0
 public static IHtmlString UploadFor <TControl>(this KenticoForm html, TControl control) where TControl : IControl
 {
     return(UploadFor(html, control, ControlRendererRegistrar.Resolve(ControlType.UploadFile)));
 }
        public static IHtmlString TextAreaFor(this KenticoForm html, IControl control)

        {
            return(TextAreaFor(html, control, ControlRendererRegistrar.Resolve(ControlType.TextArea)));
        }
示例#22
0
 public static IHtmlString BeginForm(this KenticoForm html, string action, string controllerName, string formName, ISubmissionOptions options)
 {
     return(BeginForm(html, action, controllerName, formName, "", options, "post", "block", true, false));
 }
示例#23
0
 public static IHtmlString LabelFor(this KenticoForm html, IControl control)
 {
     return(LabelFor(html, control, ControlRendererRegistrar.Resolve(ControlType.Label)));
 }