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)
        {
            string id = extraAttributes.Get("id", name);

            return(string.Format(CultureInfo.CurrentUICulture,
                                 "{0}\n<div id=\"{1}_ui\"></div>",
                                 new HiddenInput().Render(name, value == null ? this.Minimum : value, extraAttributes),
                                 id));
        }
Example #2
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)
 {
     if (DisplayInline)
     {
         string id = extraAttributes.Get("id", name);
         return(string.Format(CultureInfo.CurrentUICulture,
                              "{0}\n<div id=\"{1}_ui\"></div>",
                              new HiddenInput().Render(name, value, extraAttributes), id));
     }
     else
     {
         return(base.Render(name, value, extraAttributes));
     }
 }
Example #3
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());
        }
        public void AppendWidgetAttributesTest()
        {
            var target = new StringField();

            var test1 = new ElementAttributesDictionary();

            target.AppendWidgetAttributes(new Widgets.TextInput(), test1);
            Assert.AreEqual(null, test1.Get("maxlength", null));

            target.MaxLength = 10;

            var test2 = new ElementAttributesDictionary();

            target.AppendWidgetAttributes(new Widgets.TextArea(), test2);
            Assert.AreEqual(null, test2.Get("maxlength", null));

            var test3 = new ElementAttributesDictionary();

            target.AppendWidgetAttributes(new Widgets.TextInput(), test3);
            Assert.AreEqual("10", test3.Get("maxlength", null));
        }
        /// <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)
        {
            // Correct value
            Tuple values = value as Tuple;

            if (values == null)
            {
                values = Decompress(value);
            }

            // Allow derived classes to make final changes
            PreRenderWidgets(values);

            // Build attributes
            ElementAttributesDictionary finalAttributes = BuildAttributes(extraAttributes);
            string id = finalAttributes.Get("id", null);

            // Build output
            var output = new List <string>();

            for (int index = 0; index < Widgets.Count; index++)
            {
                // Get value
                object widgetValue = values.Get(index);

                // Update ID
                if (id != null)
                {
                    finalAttributes["id"] = string.Concat(id, "_", index);
                }

                // Render item
                output.Add(Widgets[index].Render(string.Concat(name, index), widgetValue, finalAttributes));
            }

            return(FormatOutput(output.ToArray()));
        }