The autocomplete selection box is not appearing correctly

I am attempting to implement the jquery-ui autocomplete combobox in a .Net Core 2.2 web application, but I seem to be encountering a CSS issue. Here is how it currently appears: https://i.sstatic.net/wXaBg.png

In addition to the jquery-ui CSS, I am also using datatables CSS and bootstrap CSS. This style is being applied as well:

<style>

.ui-autocomplete {
    max-height: 150px;
    overflow-y: auto;
    /* prevent horizontal scrollbar */
    overflow-x: hidden;
    z-index: 1000 /*show the dropdown over the addform*/
}

The HTML code for this section is as follows:

<div class="row">
    <div class="col-sm-3">
        <label id="PersonIdLabel" class="custom-label">Choose Person</label>
    </div>
    <div class="col-sm-3">
        <input id="PersonId" class="form-control" type="text" />
    </div>
    <div class="col-sm-3">
        <input id="PersonName" class="form-control text ui-widget-content ui-corner-all" type="text" />
    </div>
    <div class="col-sm-2">
        <a class="btn btn-sm btn-primary" asp-action="ttCreate"><span class="glyphicon glyphicon-plus"></span>New Transaction</a>
    </div>
</div>

The JavaScript keydown event function is defined as:

$('#PersonId').keydown(function () {
    //table = table.ajax.reload();
    $(this).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/Household/getPersonsJson2/",
                type: 'GET',
                dataType: "json",
                data: {
                    search_str: request.term
                },
                success: function (data) {
                    //console.log(data);
                    response(data);
                }
            });
        },
        appendTo: "#dialog-form",
        minLength: 2,
        select: function (event, ui) {
            //console.log(ui.item.label + " " + ui.item.value);
            $("#PersonName").val(ui.item.label);
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });
});

Answer №1

After some troubleshooting, I managed to resolve the issue at hand. It turns out that the problem lied in the incorrect field names being returned by the action. To rectify this, I adjusted the names to "value" and "label". This updated version of the action now appears as follows:

[HttpGet]
    public async Task<IActionResult> fetchPeopleData(string search_str)
    {
        var peopleData = await (from p in _context.Persons
                             where p.FullNameWithPLN.ToLower().Contains(search_str.ToLower())
                             select new
                             {
                                 value = p.Id,
                                 label = p.FullNameWithPLN
                             }).OrderBy(a => a.label).ToListAsync();

        return Json(peopleData);
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hiding elements in dark mode using `hidden` or `block` in Tailwind will not override its own hidden selector

To switch between dark and light mode for these two images, the dark:block selector does not override the hidden class. <div className="ml-5 content-center"> <img className="hidden dark:block h-6 w-auto my-1" src="/stati ...

The JSON ticker for BTC/LTC has stopped functioning

I've been relying on this JSON ticker for the past month and it's been smooth sailing. However, today it suddenly stopped working. Any ideas on what might have caused this issue? $(function () { startRefresh(); }); function startRefresh() { ...

JQuery GET brings back unnecessary HTML content

Currently utilizing a PHP cart class and implementing some jQuery to dynamically update a div when users add products. The issue I'm encountering is that upon adding a product, the list of products on the HTML page gets duplicated (see screenshot) ev ...

What is the best way to extract a value from a string containing a list of maps?

I am currently facing a requirement where I need to extract values from a map in the following format: "{xyz=True, abc=asd-1123, uvw=null}" The challenge is to retrieve these values from a string representation of the map. I have attempted usi ...

Complete the execution of the jQuery function

It may seem like a simple idea - to stop executing a function, just use return false, return, or call on a function like undefined. However, in this case, it's not that straightforward. I'm working on a website project that includes a snake game ...

Is nesting possible with the &:extend function in LessCss?

I've recently been exploring the Less &:extend feature. My goal is to nest multiple extends - essentially extending a class that itself extends another class. However, after testing it out, I'm not sure if it's working as expected. It ...

Error: Encountered an unexpected token while trying to parse multiple form functions

I recently added the following submission function to my .js file: $( "form" ).on( "submit", function( event ) { event.preventDefault(); var data = $( this ).serialize(); $.ajax({ type: "POST", url: "content/rev/a_sub ...

Tips for effectively deleting a flash object from an HTML page

I recently created a website with AJAX (using jquery) for navigation purposes. The pages on the site slide smoothly, and I have been using remove() to get rid of the old page. Everything was working fine until I encountered an issue where the browser cras ...

The jQuery plugin fails to display properly when used in conjunction with AngularJS

Currently, I am working on a tabs application and have implemented an angularJS directive to utilize the jquery tabs plugin. Unfortunately, I am facing issues with the view not updating properly and the tabs not being displayed as expected. Here is a link ...

Is there a way to automatically scroll to a sidebar item when clicking on a marker?

Is it possible to make the sidebar scroll to the item clicked on the marker? I saw this functionality on a website like this one. Any ideas on how to achieve this would be appreciated. Thanks! This div contains map id & side_bar id. <div style="wi ...

Why does using rgba color with an alpha value cause my div to become see-through?

I am currently attempting to assign a background color to a specific style of pop-up, but whenever I use a value that includes an alpha channel, it ends up being transparent. This is the CSS code I have been using: --color: 255, 144, 106, 0.18; background ...

Gulp fails to generate a CSS file after compiling Sass to CSS

Recently, I've been having trouble compiling my sass file to css. Even though it was working fine before and I haven't made any changes, now my CSS file is empty. Below is the task I am trying to accomplish: gulp.task('sass', function ...

Steps to fix issues with Cross-Origin Read Blocking (CORB) preventing cross-origin responses and Cross Origin errors

var bodyFormData = new FormData(); bodyFormData.set("data", "C://Users//harshit.tDownloads\\weather.csv"); bodyFormData.set("type", "text-intent"); //axios.post("https://api.einstein.ai/v2/language/datasets/upload", axio ...

Querying JSON Data in an Ajax Request: A Simple Guide

I have a data file in json format that looks like this: {"markers":[ { "latitude":11.58655, "longitude":122.755402, "type":"A"}, { "latitude":11.00698, "longitude":124.612801, "type":"B"}, { "latitude":10.30723, "longitude":123.898399, "type": ...

Having trouble resizing divisions using three.js?

Three.js is an incredible library that offers thorough documentation and functions perfectly. I am currently attempting to display a plane with trackball control inside a div that resizes according to the window or browser size. However, I am encountering ...

Updating part of a page while also changing the navigation

Apologies in advance, as this is my first attempt at coding a website. I have a specific need where I want to update only one div on my web page when a link in the navigation bar is clicked. <body> <div id="wrapper"> <header id= ...

Implement the MathJax package for automatic word wrapping of mathematical

I have implemented additional processing for MathJax using the following code snippet: <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"],["\\(","\\)"]] }, "HTML-CSS": { ...

The initial item on the list, displayed on the right side in Google Chrome

Currently experiencing an issue with Google Chrome where the first list item's bullet is floating right while all other list items' bullets are aligned correctly at left. Here is the code snippet causing the problem: <div class="window_sub_ ...

Using props as classnames in next.js applications

I am currently attempting to create a dynamic header for each page of my app that changes color based on the current page. Here is my approach: <Header className="headerBitcoin"></Header> My goal is to have the same header component ...

Placement: fresh column in absolute position

Could someone please help me understand this situation? I have posted my code on jsfiddle. I am using Bootstrap 4. In my design, I have text placed over an image with the parent div having position:relative. The left div has position:absolute and left:2%, ...