Unplanned
Last Updated: 17 Jan 2024 07:23 by ADMIN
Ben
Created on: 24 Dec 2023 13:59
Category: UI for Blazor
Type: Feature Request
1
Strongly typed value bindings

Hi,

I am looking to use strongly-typed IDs in my project and it does not appear to be possible to achieve this with Telerik UI for Blazor. Instead, the popup does not go away on selection and the bound value does not update.

Note that this is not a request for binding to arbitrary complex types. I believe it would be sufficient to support value types that implement ToString / IParsable.

For example:

https://blazorrepl.telerik.com/QxvcQIPR55jFAGMF00

<h1>Hello, Telerik REPL for Blazor!</h1>
<h2>Selected Value: @SelectedValue</h2>

<TelerikDropDownList Data="@Data"
    @bind-Value="@SelectedValue"
    TextField="@nameof(SelectItem.DisplayName)"
    ValueField="@nameof(SelectItem.Value)"
    DefaultText="Select ...">
</TelerikDropDownList>

@code {
    public MyValue SelectedValue {get; set;}
    public SelectItem[] Data { get; } = new[] {
        new SelectItem(1),
        new SelectItem(2),
    };

    public readonly struct MyValue : System.IParsable<MyValue> {
        public int Value {get;}

        public MyValue(int value) {
            this.Value = value;
        }

        public override string ToString() {
            return Value.ToString();
        }

        public static MyValue Parse(string str, IFormatProvider provider) {
            return new(int.Parse(str, provider));
        }

        public static bool TryParse(string str, IFormatProvider provider, out MyValue value) {
            value = new(int.Parse(str, provider));
            return true;
        }
    }

    public class SelectItem {
        public SelectItem(int value) {
            Value = new(value);
            DisplayName = $"Item {value}";
        }

        public MyValue Value {get; set;}
        public string DisplayName {get; set;}
    }
}

Thanks,
Ben

6 comments
ADMIN
Tsvetomir
Posted on: 17 Jan 2024 07:23

Hi Ben,

Yes, this is correct. The item has been approved but has not yet been triaged for further research and development. The item's priority is mainly demand-driven, the more votes and popularity it gathers - the more likely it is to be implemented in an upcoming release. Of course, our project management team monitors the feedback portal and can influence the priority of a given item. 

To be sure you are not missing anything related to this item, I recommend subscribing so that if a change in the state occurs, namely being "Planned" or going "In Development", you'll get notified.

Kind regards,
Tsvetomir
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Ben
Posted on: 16 Jan 2024 13:37

Hi Tsvetomir,

Thanks for the update - can you please advise what "unplanned" means? I am assuming it means that Telerik consider it a valid request but have no planned delivery date - is that fair?

Thanks,
Ben

ADMIN
Tsvetomir
Posted on: 16 Jan 2024 13:33

Hi, Ben,

Thank you for your valuable insights! Indeed, I am marking the item as "Unplanned".

Subscribe to the item so that you get notified whenever a change in its status occurs. 

Regards,
Tsvetomir
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Ben
Posted on: 27 Dec 2023 14:34

I also created an example of how this can be done using a raw select element in Blazor: https://blazorrepl.telerik.com/wdbQwVPy32mK6zuo17.

I'd be quite happy to write my own TypeConverter implementations if the Telerik DropDownList was able to use these.

Ben
Posted on: 27 Dec 2023 12:08

Hi Tsvetomir,

Thanks for your reply.

> Providing such functionality might lead to difficulties in implementing validation and data operations such as filtering.

I've seen this reasoning given in the complex data type binding thread as well. However, I'd like to clarify what filtering issues you forsee - my understanding is that the DropDownList component only filters on the TextField property, not on the ValueField property. As such, it shouldn't matter what the CLR Type of the bound value is?

> Even though the comparison of the structs is more similar to the primitive data type comparison rather than reference type comparisons, there might be occasions in which the default comparison of the struct might not be sufficient.

Do you have any examples of potential issues? The DropDownList already presumably round-trips primitive types to strings and back via default parse methods?

> Since the model extraction knowledge base article, we have not seen much demand for such an implementation. Is there a scenario that is not covered by the example?

The article shows a workaround which either needs to be implemented for every individual dropdown (which bloats every page / component that uses a dropdown, some pages may contain multiple dropdowns), or needs to be used as the basis for a custom component (which defeats the point of buying a third-party component suite). While I believe that the example can technically be made to work, I don't believe it represents good software engineering for the long-term maintainability and readability of our codebase.

Thanks,
Ben

ADMIN
Tsvetomir
Posted on: 26 Dec 2023 08:27

Hi, Ben, 

Thank you for taking the time to create and share a sample. Indeed, the struct data types still fall within the complex data type limitations outlined in the original feedback portal item regarding complex data type binding.

Providing such functionality might lead to difficulties in implementing validation and data operations such as filtering. Even though the comparison of the structs is more similar to the primitive data type comparison rather than reference type comparisons, there might be occasions in which the default comparison of the struct might not be sufficient. If we decide to expose a functionality, we aim at making it robust. 

Since the model extraction knowledge base article, we have not seen much demand for such an implementation. Is there a scenario that is not covered by the example?

Regards,
Tsvetomir
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!