Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

[Question] Are you able to just use strings for Value and date related bindings on the control? #286

Open
grofit opened this issue Aug 10, 2022 · 0 comments
Labels
Question Question about this project Triage Issue needs to be triaged

Comments

@grofit
Copy link

grofit commented Aug 10, 2022

I have a scenario where I want to basically use it like an input box but have any close matches provided to the user, basically the same as #103 but I can see you added it in another way so it always gets added to the list.

Anyway the problem im having is that it doesnt seem to like me passing in a string as the Value, like here is an example of what I mean:

<BlazoredTypeahead SearchMethod="SearchData" @bind-Value="Value" AddItemOnEmptyResultMethod="AddManualEntry">
    <SelectedTemplate>
        @context
    </SelectedTemplate>
    <ResultTemplate>
        @context
    </ResultTemplate>
</BlazoredTypeahead>

@code {

    [Parameter]
    public string Value { get; set; }
    
    [Parameter]
    public List<string> Data { get; set; }

    private async Task<IEnumerable<string>> SearchData(string searchText) 
    { return Data.Where(x => x.Contains(searchText, StringComparison.OrdinalIgnoreCase));}

    private async Task<string> AddManualEntry(string arg)
    {
        Data.Add(arg);
        return arg;
    }
}

So this component wraps your component and basically just wants to be passed a string which is the value of the element and then a list of possible values for it to filter on.

The problem is while it does have the initial value there, no subsequent changes seem to get bubbled back out to the parent component, all the examples are using complex data but really im just after a simple ComboBox style element, but this is the closest one I can fine online.

I assumed that while it was bound maybe it wouldnt bubble up so I probably needed to expose an EventCallback<string> and then use the ValueChanged property of your control to propagate and changed the @bind-Value="Value" to Value="@Value", however whenever I do that I just get the error:

,"Value cannot be null. (Parameter \u0027accessor\u0027)"," at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create[TField](Expression\u00601 accessor)\r\n at Blazored.Typeahead.Blazor
edTypeahead\u00602.OnInitialized()

Value definitely has a value as im showing it elsewhere on the containing page, so could anyone point me in the direction of where im going wrong or if this control cant be used this way.

Thanks!

@grofit grofit added Question Question about this project Triage Issue needs to be triaged labels Aug 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question Question about this project Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant