Example #1
0
        /// <summary>
        /// Create new ElementAttributesDictionary populated by object.
        /// </summary>
        /// <param name="attributes">Anon object.</param>
        /// <returns>New ElementAttributesDictionary.</returns>
        public static ElementAttributesDictionary Create(object attributes)
        {
            var attrs = new ElementAttributesDictionary();

            attrs.AppendObject(attributes);
            return(attrs);
        }
Example #2
0
        /// <summary>
        /// Apply a label element to string content.
        /// </summary>
        /// <param name="contents">Content to tag.</param>
        /// <param name="attributes">Attributes to apply.</param>
        /// <returns></returns>
        public string ApplyLabel(string contents, ElementAttributesDictionary attributes)
        {
            const string labelFormat = "<label for=\"{0}\"{1}>{2}</label>";
            IWidget      widget      = _field.Widget;

            // Tag with label if we have an ID
            string id = widget.GetAttributes().Get("id");

            if (string.IsNullOrEmpty(id))
            {
                id = this.AutoId;
            }
            if (!string.IsNullOrEmpty(id))
            {
                string attrs = attributes == null ? "" : attributes.ToString();
                contents = string.Format(CultureInfo.CurrentUICulture, labelFormat,
                                         widget.IdForLabel(id), attrs, contents);
            }
            return(contents);
        }
Example #3
0
        /// <summary>
        /// Renders the field by rendering the passed widget, adding any HTML
        /// attributes passed as attrs.
        /// </summary>
        /// <param name="widget">Widget to render.</param>
        /// <param name="attributes">Additional attributes for widget.</param>
        /// <returns>Widget rendered as string.</returns>
        public string AsWidget(IWidget widget, ElementAttributesDictionary attributes)
        {
            if (widget == null)
            {
                widget = this._field.Widget;
            }
            if (attributes == null)
            {
                attributes = new ElementAttributesDictionary();
            }

            // Assign additional attributes by field
            this._field.AppendWidgetAttributes(widget, attributes);

            // Add ID
            if (!(attributes.ContainsKey("id") || widget.GetAttributes().ContainsKey("id")))
            {
                attributes["id"] = this.AutoId;
            }

            return(widget.Render(this.HtmlName, this.DataValue, attributes));
        }
Example #4
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="source"></param>
 public ElementAttributesDictionary(ElementAttributesDictionary source)
     : base(source.Count)
 {
     this.Append(source);
 }
Example #5
0
 /// <summary>
 /// Output a string version of this field
 /// </summary>
 /// <param name="attributes">Additional attributes for widget.</param>
 /// <returns></returns>
 public string ToString(object attributes)
 {
     return(this.AsWidget(null, ElementAttributesDictionary.Create(attributes)));
 }
Example #6
0
 /// <summary>
 /// Apply a label element to string content.
 /// </summary>
 /// <param name="contents">Content to tag.</param>
 /// <param name="attributes">Attributes to apply.</param>
 /// <returns></returns>
 public string ApplyLabel(string contents, object attributes)
 {
     return(ApplyLabel(contents, ElementAttributesDictionary.Create(attributes)));
 }
Example #7
0
 /// <summary>
 /// Apply a label element to string content.
 /// </summary>
 /// <param name="attributes">Attributes to apply.</param>
 /// <returns></returns>
 public string ApplyLabel(ElementAttributesDictionary attributes)
 {
     return(ApplyLabel(this.Label, attributes));
 }
Example #8
0
 /// <summary>
 /// Apply a label element to string content.
 /// </summary>
 /// <param name="attributes">Attributes to apply.</param>
 /// <returns></returns>
 public string ApplyLabel(object attributes)
 {
     return(ApplyLabel(this.Label, ElementAttributesDictionary.Create(attributes)));
 }
Example #9
0
 /// <summary>
 /// Returns a string of HTML for representing this as an <input type="hidden" />.
 /// </summary>
 /// <param name="attributes">Additional attributes for widget.</param>
 /// <returns>Widget rendered as string.</returns>
 public string AsHidden(ElementAttributesDictionary attributes)
 {
     return(AsWidget(new Widgets.HiddenInput(), attributes));
 }
Example #10
0
 /// <summary>
 /// Returns a string of HTML for representing this as an <textarea></textarea>.
 /// </summary>
 /// <param name="attributes">Additional attributes for widget.</param>
 /// <returns>Widget rendered as string.</returns>
 public string AsTextArea(ElementAttributesDictionary attributes)
 {
     return(AsWidget(new Widgets.TextArea(), attributes));
 }