The library I am using has the following signature that includes the ElementReference of the input field. How do I get that from the RadzenTextBox component?
public static Task<Autocomplete> CreateAsync(IJSRuntime jsRuntime, ElementReference inputField, AutocompleteOptions opts = null);
The following line is failing: Cannot implicitly convert type 'Radzen.Blazor.RadzenTextBox' to 'Microsoft.AspNetCore.Components.ElementReference'
<RadzenTextBox style="width: 100%;" @ref="this.addressBox" Name="BusinessAddress1" value="@formattedAddress" />
enchev
February 17, 2022, 1:14pm
2
You can use Element property of every Radzen component. Check this demo for reference:
https://blazor.radzen.com/tooltip
1 Like
In that example, the component is passing the element property on an event.
I need to get the element property during "OnAfterRenderAsync" to use with the method referenced in the question.
CreateAsync(JSRuntime, this.addressBox, new AutocompleteOptions
This code works with native HTML
<Input type="text" id="Address" @ref="this.addressBox" value="@formattedAddress" />
enchev
February 17, 2022, 2:27pm
4
barry8schneider:
native HTML
References to native HTML elements are ElementReference, as I said in my previous reply you can use Element property of the Radzen component reference. For example:
<RadzenTextBox @ref="textBox" ..
...
@code {
RadzenTextBox textBox;
protected override Task OnAfterRenderAsync(bool firstRender)
{
var textBoxElement = textBox.Element;
return base.OnAfterRenderAsync(firstRender);
}
}
Thanks, that worked. exactly the info I needed.
This doesn't seem to work for RadzenTreeItem, is there a way to get the ElementReference for one of these?