We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamically adding a OnValueSelect results in the list text not being rendered properly

Not sure if this is a bug or I'm missing something in when builder the rendertree but when trying to add a dynamically created combobox the combobox renders and binds to the data but the text values all appear to be empty. Here's a sample code fragment i'm using:


I should add that the event is being called fine - but nothing is show for each item in the bound list, it also appears that if I switch the render order so the field setting are rendered after the event call back then the combo displays correctly but the event never fires.


I've  also discovered that if I swap the childcontent section in debug with a hot reload it works as expected


Thanks


var propInfoValue = o.GetType().GetProperty(propertyInfo.Name);

var constant = System.Linq.Expressions.Expression.Constant(o, o.GetType());

var exp = System.Linq.Expressions.MemberExpression.Property(constant, propertyInfo.Name);

builder.OpenComponent(0, typeof(Syncfusion.Blazor.DropDowns.SfComboBox));

builder.AddAttribute(1, "DataSource", sharedLookup.GetItems());

var defaultValue = propInfoValue.GetValue(o);

builder.AddAttribute(2, "Value", defaultValue);

builder.AddAttribute(3, "PlaceHolder", DisplayName);

builder.AddAttribute(4, "FloatLabelType", FloatLabelType.Always);

builder.AddAttribute(5, "ChildContent", (Microsoft.AspNetCore.Components.RenderFragment)((fieldSettingBuilder) =>

{

fieldSettingBuilder.OpenComponent(1);

fieldSettingBuilder.AddAttribute(2, "Value", "ID");

fieldSettingBuilder.AddAttribute(3, "Text", "Name");

fieldSettingBuilder.CloseComponent();

}));

builder.AddAttribute(6, "ChildContent", (Microsoft.AspNetCore.Components.RenderFragment)((builderComboBoxEvents) =>

{

builderComboBoxEvents.OpenComponent>(1);

builderComboBoxEvents.AddAttribute(2, "OnValueSelect", EventCallback.Factory.CreateLookupEntry >>(this, ((e) => OnValueSelect(e))));

builderComboBoxEvents.CloseComponent();

}));


builder.CloseComponent();


2 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team December 19, 2022 11:14 AM UTC

Hi Richard,

You can achieve your requirement by using the below code example on your application.

Find the code example here:

 

                                              b.AddAttribute(10, "ChildContent", (RenderFragment)(b2 =>

                                              {

                                                    b2.OpenComponent<ComboBoxEvents<string, ComboData>>(11);

                                                    b2.AddAttribute(12, "OnValueSelect", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(EventCallback.Factory.Create<SelectEventArgs<string>>(this, DropDownChange)));

                                                    b2.CloseComponent();

 

                                                    b2.OpenComponent<ComboBoxFieldSettings>(13);

                                                    b2.AddAttribute(14, "Value", "DisplayValue");

                                                    b2.CloseComponent();

 

                                              }));

 

                                          b.CloseComponent();

                                          b.CloseElement();

                                       };


Regards,

Sureshkumar P


Marked as answer

RK Richard Kiernan December 19, 2022 11:25 AM UTC

Perfect thanks


R


Loader.
Live Chat Icon For mobile
Up arrow icon