Declined
Last Updated: 10 Jun 2021 06:39 by ADMIN
Kyle
Created on: 01 Nov 2014 13:00
Category: UI for ASP.NET MVC
Type: Feature Request
6
extend the WidgetBuilder implementation support extensible fluent method chaining
I would expect a fluent method chain to not produce side effects when a method is invoked more than once.  particularly, concerning the ability to apply HtmlAttributes more than once to a method chain.  This prevents me from implementing meaningful extension methods to promote a DRY approach to views. 

In particular, I am trying to do something like this:

public static TextBoxBuilder<TProperty> PasswordFor<TModel, TProperty>(this WidgetFactory<TModel> widgetFactory, Expression<Func<TModel, TProperty>> expression)
        {
            return widgetFactory.TextBoxFor(expression).HtmlAttributes(new { type = "password" });
        }

        public static TextBoxBuilder<TModel> AutoFocus<TModel>(this TextBoxBuilder<TModel> builder)
        {
            return builder.HtmlAttributes(new { autofocus = true });
        }


I am finding that because the HTML attributes is cleared in your base implementation.. 

this.Component.HtmlAttributes.Clear();


it doesn't support an aggregation of attributes, but instead it's last-man-in.   that defeats the purpose of extensibility and effectively insists upon repetition and sort of brittle design that a copy/paste architecture results in.

I would believe it be completely acceptable to give the last-attribute-applied precedence and overwrite the value, but the reality is that we're talking about basic key/value pairs, and it shouldn't be difficult to merge the attributes as they are built.   best case, right now i have to implement my own derivation of the WidgetBuilderBase and implement an extension method off the WidgetFactory that bootstraps my functionality - certainly not a stretch, but more work than should probably be necessary.



   
    public virtual TBuilder HtmlAttributes(object attributes)
    {
      return this.HtmlAttributes(ObjectExtensions.ToDictionary(attributes));
    }

    public virtual TBuilder HtmlAttributes(IDictionary<string, object> attributes)
    {
      this.Component.HtmlAttributes.Clear();
      Kendo.Mvc.Extensions.DictionaryExtensions.Merge(this.Component.HtmlAttributes, attributes);
      return this as TBuilder;
    }
3 comments
ADMIN
Viktor Tachev
Posted on: 10 Jun 2021 06:39

Hi,

We are closing this request due to lack of interest from the community.

Regards,
Viktor Tachev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

ADMIN
Telerik Admin
Posted on: 07 Nov 2014 16:46
kc, can you share your implementation in the comments section? Thus other users searching for something similar can benefit from it. Thanks in advance.
Kyle
Posted on: 07 Nov 2014 16:00
while it would be nice to have this functionality implemented as part of the out-of-the-box package, I have found a workaround using a series of extension methods that exploit the .ToComponent method that grants access directly to the underlying component.