/// <summary>
        /// Returns HTML for an &lt;input&gt; HTML element.
        /// </summary>
        /// <param name="inputType">The type of input to produce</param>
        /// <param name="fieldConfiguration">The field configuration to use for attributes and format string</param>
        /// <returns>The HTML of the input element</returns>
        protected IHtmlContent GetInputHtml(TextInputType inputType, IReadonlyFieldConfiguration fieldConfiguration)
        {
            if (inputType == TextInputType.Password)
            {
                return(FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, fieldConfiguration.HtmlAttributes));
            }

            var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes);

            if (!attrs.Attributes.ContainsKey("type"))
            {
                attrs = attrs.Attr(type => inputType.ToString().ToLower());
            }

            IHtmlContent htmlContent;

            if (!string.IsNullOrEmpty(fieldConfiguration.FormatString))
            {
                htmlContent = FieldGenerator.HtmlHelper.TextBoxFor(
                    FieldGenerator.FieldProperty,
                    fieldConfiguration.FormatString,
                    attrs.ToDictionary()
                    );
            }
            else
            {
                htmlContent = FieldGenerator.HtmlHelper.TextBoxFor(
                    FieldGenerator.FieldProperty,
                    attrs.ToDictionary()
                    );
            }

            return(htmlContent);
        }
Пример #2
0
        protected Nancy.ViewEngines.Razor.IHtmlString GetInputHtml(TextInputType inputType)
        {
            ///TODO: GB fix this so it renders the password with the correct attributes:
            if (inputType == TextInputType.Password)
            {
                return(new NonEncodedHtmlString(string.Format(@"<input type=""password"" id="""" name="""" class="""" />")));
            }
            //return FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, FieldConfiguration.HtmlAttributes);

            var attrs = new HtmlAttributes(FieldConfiguration.HtmlAttributes);

            attrs.Attr(type => inputType.ToString().ToLower());
            return(!string.IsNullOrEmpty(FieldConfiguration.FormatString)
                ? FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, FieldConfiguration.FormatString, attrs.ToDictionary())
                : FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, attrs.ToDictionary()));
        }