Duplicated
Last Updated: 01 Mar 2021 07:39 by ADMIN
Mr.Ali
Created on: 25 Feb 2021 12:33
Category: UI for Blazor
Type: Feature Request
0
How to define event for each control for Form - Auto Generated

Hi,

I have seen Form - Auto-Generated sample in Blazor which is nice and handy, but what should I do, if I need to define a Dynamic event by code for a dropdown change for example ?

 

I might need to define and handle an event for each control that is dynamically generated. I hope someone can help.

 

Regards

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
4 comments
ADMIN
Marin Bratanov
Posted on: 01 Mar 2021 07:39

We believe there can be use for an "OnUpdate" event on the form and you can Follow that here: https://feedback.telerik.com/blazor/1508940-add-onupdate-event. At the moment, I am marking this as a duplicate to it, and if a discussion here comes up with a different scenario/requirement/feature, we can discuss that as needed.

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ADMIN
Marin Bratanov
Posted on: 26 Feb 2021 08:05

Hello Ali,

What you are referring to is no longer an autogenerated form, but something you need to customize through the FormItems feature and their Templates. A list of countries is not a data source that the form could generate on its own anyway - it would generate a dropdown for enums (see more here).

My colleague Ed made a sample for you on adding custom editors with custom data source and event handling in your Twitter thread here. You can extend it to add the desired logic.

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Mr.Ali
Posted on: 26 Feb 2021 01:48

Thanks sir,

 

Let me make myself a bit more clear. Please look this example :  https://demos.telerik.com/blazor-ui/form/auto-generated

 

Imagine Need to define 2 Dropdown and 3 TxtBox dynamically the then define an event for one of the Dropdowns which shows a list of countries and when the user selected "UK" 2 other controls should be disabled or hidden !.

Is this possible now ?. If yes, is there any sample ?

ADMIN
Marin Bratanov
Posted on: 25 Feb 2021 19:52

Hello Ali,

I can see a few options and I'd appreciate your thoughts on them so we can see how you imagine such an event:

  • simply define the desired form items and use custom editors where you need that event, otherwise you could keep using the built-in ones
  • perhaps we could expose an event like OnChange that would receive as an argument the field name or FieldIdentifier for the field, and an object with the new value (it would already be in the model too because of the two-way binding) so you could perform some logic - such an event would probably fire for all fields and it would be up to the app to distinguish when and what to do with that
  • you can simply define your own EditForm as usual to use the components and events like you would normally do, and simply enhance it with the other prettier validation tools we have (see more here).

It is important to keep in mind that exposing a ValueChanged event would mean that the form can no longer use two-way binding, which would kind of defeat its purpose - in Blazor the <Parameter> and <Parameter>Changed are the pair that produces two way binding and you cannot use them together (you can read more here). So, even ignoring the technical complexity of exposing that, it would rather destroy the Form component itself.

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.