Example #1
0
        /// <summary>
        /// Returns this Widget rendered as HTML
        /// </summary>
        /// <param name="name">Form name of the widget being renderd</param>
        /// <param name="value">Value of the field being rendered</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes.SetDefault("cols", "40");
            finalAttributes.SetDefault("rows", "10");
            finalAttributes.SetDefault("name", name);
            if (value == null)
            {
                value = string.Empty;
            }
            return(string.Format(CultureInfo.InstalledUICulture,
                                 "<textarea{0}>{1}</textarea>", finalAttributes, value));
        }
        /// <summary>
        /// Returns this Widget rendered as HTML.
        /// </summary>
        /// <param name="name">Form name of the widget being renderd.</param>
        /// <param name="value">Value of the field being rendered.</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity.</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            StringBuilder sb = new StringBuilder();
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes["multiple"] = "multiple";
            finalAttributes.SetDefault("name", name);

            // Create selected choices list
            IList <object> selectedChoices = value as List <object>;

            if (selectedChoices == null)
            {
                if (value != null && !string.Empty.Equals(value))
                {
                    selectedChoices = new object[] { value }
                }
                ;
            }

            // Render output
            sb.AppendFormat(CultureInfo.CurrentUICulture, "<select{0}>\n", finalAttributes);
            RenderOptions(sb, selectedChoices);
            sb.Append("</select>");

            return(sb.ToString());
        }
Example #3
0
        /// <summary>
        /// Render a single choice item into HTML.
        /// </summary>
        /// <param name="output">Append output to this string builder.</param>
        /// <param name="name">Form name of the item being rendered.</param>
        /// <param name="value">Choice item being rendered.</param>
        public override void RenderItemChoice(StringBuilder output, string name, object value)
        {
            var attributes = new ElementAttributesDictionary();

            attributes.SetDefault("class", ItemCssClass);
            output.AppendFormat(CultureInfo.InvariantCulture, "<li{0}>{1}{2}</li>",
                                attributes, value, new HiddenInput().Render(name, value));
        }
Example #4
0
 /// <summary>
 /// Additional attributes to assign to widget on render.
 /// </summary>
 /// <param name="widget">Widget attributes are targeted at.</param>
 /// <param name="attributes">Attributes to append to.</param>
 public override void AppendWidgetAttributes(IWidget widget, ElementAttributesDictionary attributes)
 {
     base.AppendWidgetAttributes(widget, attributes);
     if (this.MaxLength != null && widget is Widgets.TextInput)
     {
         attributes.SetDefault("maxlength", this.MaxLength.ToString());
     }
 }
Example #5
0
        /// <summary>
        /// Returns this Widget rendered as HTML
        /// </summary>
        /// <param name="name">Form name of the widget being renderd</param>
        /// <param name="value">Value of the field being rendered</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes["keytype"] = "rsa"; // Override any other value
            finalAttributes.SetDefault("name", name);
            return(string.Format(CultureInfo.CurrentUICulture, "<keygen{0} />", finalAttributes));
        }
Example #6
0
        /// <summary>
        /// Returns this Widget rendered as HTML
        /// </summary>
        /// <param name="name">Form name of the widget being renderd</param>
        /// <param name="value">Value of the field being rendered</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes["type"] = this.inputType; // Override any other value
            finalAttributes.SetDefault("name", name);
            if (DisableAutoComplete)
            {
                finalAttributes.SetDefault("autocomplete", "off");
            }
            if (value != null)
            {
                string stringValue = value.ToString();
                if (!string.IsNullOrEmpty(stringValue))
                {
                    finalAttributes.SetDefault("value", stringValue);
                }
            }
            return(string.Format(CultureInfo.InstalledUICulture, "<input{0} />", finalAttributes.ToString()));
        }
Example #7
0
        /// <summary>
        /// Returns this Widget rendered as HTML
        /// </summary>
        /// <param name="name">Form name of the widget being renderd</param>
        /// <param name="value">Value of the field being rendered</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes["type"] = "checkbox"; // Override any other value
            finalAttributes.SetDefault("name", name);

            bool result = _checkedTest(value);

            if (result)
            {
                finalAttributes.SetDefault("checked", "checked");
            }
            if (value != null)
            {
                finalAttributes.SetDefault("value", value.ToString());
            }

            return(string.Format(CultureInfo.CurrentUICulture, "<input{0} />", finalAttributes));
        }
Example #8
0
        /// <summary>
        /// Returns this Widget rendered as HTML.
        /// </summary>
        /// <param name="name">Form name of the widget being renderd.</param>
        /// <param name="value">Value of the field being rendered.</param>
        /// <param name="extraAttributes">Attributes to assign to HTML entity.</param>
        /// <returns>HTML</returns>
        public override string Render(string name, object value, ElementAttributesDictionary extraAttributes)
        {
            const string forFormat  = " for=\"{0}\"";
            const string itemFormat = "<li><label{0}>{1} {2}</label></li>\n";

            StringBuilder sb = new StringBuilder();

            // Setup attributes
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);

            finalAttributes.SetDefault("name", name);
            string id = finalAttributes.Get("id");

            // Create selected choices list
            IList <object> selectedChoices = ConversionHelper.ObjectList(value);

            // Render choices
            sb.Append("<ul>\n");
            int index = 0;

            foreach (IChoice choice in Choices)
            {
                // Generate label id
                string labelFor = string.Empty;
                if (!string.IsNullOrEmpty(id))
                {
                    string newId = string.Concat(id, "_", index.ToString(CultureInfo.InvariantCulture));
                    finalAttributes["id"] = newId;
                    labelFor = string.Format(CultureInfo.CurrentUICulture, forFormat, newId, index++);
                }

                // Render checkbox
                var cb = new CheckBoxInput()
                {
                    Attributes = finalAttributes,
                    CheckTest  = v => selectedChoices == null ? false : selectedChoices.Contains(v) // Lambda expression
                };
                string renderedCb = cb.Render(name, choice.Value);
                sb.AppendFormat(CultureInfo.CurrentUICulture, itemFormat,
                                labelFor, renderedCb, HttpUtility.HtmlEncode(choice.Label));
            }
            sb.Append("</ul>");

            return(sb.ToString());
        }