question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSException after clicking on a link inside SelectedTemplate

See original GitHub issue

How to reproduce:

  1. Create a blazor server-side project with the template in VS 2019 16.4(+)
  2. Setup BlazoredTypeahead, like described in your documentation.
  3. Add a razor page under “Pages”, e.g. “Issue.razor” with the following content:
@page "/issue"
<EditForm Model="Model">
    <BlazoredTypeahead 
                        SearchMethod="MySearchAsync"
                        @bind-Value="Model.Foo"
                        EnableDropDown="true"
                        placeholder="Search ..."
                        id="foo">
        <SelectedTemplate Context="item">
            <NavLink href="counter">@item</NavLink>
        </SelectedTemplate>
        <ResultTemplate Context="item">
            @item
        </ResultTemplate>
    </BlazoredTypeahead>
</EditForm>

@code {

    private MyModel Model { get; set; } = new MyModel();

    private Task<IEnumerable<string>> MySearchAsync(string input)
    {
        return Task.FromResult(Enumerable.Range(1, 3).Select(i => $"My Entry {i}"));
    }

    class MyModel
    {
        public string Foo { get; set; }
    }
}
  1. Edit NavMenu.razor, add a new entry:
        <li class="nav-item px-3">
            <NavLink class="nav-link" href="issue">
                <span class="oi oi-list-rich" aria-hidden="true"></span> Test issue
            </NavLink>
        </li>
  1. Start the app, go to the page “Test issue”
  2. Select an item
  3. Click on the link which was generated for the current item
  4. -> Exception in BlazoredTypeahead`2.HandleClickOnMask:
Microsoft.JSInterop.JSException: 'element is null
setFocus@https://localhost:44356/_content/Blazored.Typeahead/blazored-typeahead.js:4:9
beginInvokeJSFromDotNet/r<@https://localhost:44356/_framework/blazor.server.js:8:31421
beginInvokeJSFromDotNet@https://localhost:44356/_framework/blazor.server.js:8:31390
C</e.prototype.invokeClientMethod/<@https://localhost:44356/_framework/blazor.server.js:1:19202
C</e.prototype.invokeClientMethod@https://localhost:44356/_framework/blazor.server.js:1:19173
C</e.prototype.processIncomingData@https://localhost:44356/_framework/blazor.server.js:1:17165
e/this.connection.onreceive@https://localhost:44356/_framework/blazor.server.js:1:10276
A</e.prototype.connect/</</</i.onmessage@https://localhost:44356/_framework/blazor.server.js:1:38091
'

Hint: If you look at the code of HandleClickOnMask, it waits 250 ms from the click to the javascript interop call. During this waiting time, the html element probably got removed at the browser side.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrissaintycommented, Feb 23, 2020

@sven-n Well, that’s handy! 😃 We’ll get this shipped soon.

0reactions
chrissaintycommented, Mar 5, 2020

Thanks for letting us know @trademark18. I’m working on a big update to Blazored Modal that I’m trying to get out this week. Once that is done I’ll get back over to Typeahead and look to ship a new version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storing HREF value after clicking link - javascript
My idea was to store the HREF value from the clicked link, and then use this href value to have the page scroll...
Read more >
Clicking Anchor link, it gets appended in URL. How to stop it?
Solved: Hi, I'm using anchor links in page for some purpose within it. But when anchor link is clicked, it gets appended to...
Read more >
Back to Basics: Non-Navigating Links for JavaScript Handling
When you're creating <a href> links that are non-navigating and handled via script code or through some JavaScript framework, how exactly do ...
Read more >
Creating Anchor Links in Blazor Applications
The problem with anchor links is that when you click on them, the page won't scroll to the element you've specified in the...
Read more >
Click link with javascript does not open link.
Hi all. I am having an issue trying to get PAD to click the link which would open a download option but it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found