Received a collection of null values within the Semantic UI search dropdown

In my rails + angular application, I am utilizing semantic ui. There is a search dropdown that displays undefined values when typing the letter s, but works fine for other single letters. Strangely, no server request is made when typing the letter s, and I'm struggling to understand why this is happening. Below is the code snippet, any help would be appreciated.

Here is the JavaScript code:

$('.ui.product.search').dropdown({
    fullTextSearch: true,
    preserveHTML: false,
    debug: true,
    saveRemoteData: false,
    sortSelect: true,
    match: 'text',
    regExp: {
        escape: /[-[\]{}()*+?.,\\^$|#\s]/g,
    },
    apiSettings: {
        url: '/gpr/v1/product_codes/search?name={query}',
    },
});

And here is the Rails controller action:

def search
  # byebug
  search_query = ""
  if not params[:name].blank?
    search_query = "%#{params[:name]}%"
  end
  @product_codes = ProductCode.where("H3Description LIKE ?", search_query)
  #render json: {results: @product_codes }
end

Lastly, the HTML code:

<div class="two fields">
    <div class="field">
        <label><%= t 'asset.create.h3' %></label>
        <select name="products" class="ui product search dropdown" ng-model="asset_details[0].type_details[$index].crop">
        </select>
    </div>

Answer №1

The custom regex setting you've chosen matches the default setting, so modifying those lines won't have any impact on how it functions.

To demonstrate this, I created a simplified example in Codepen using your provided code. In the example, a single "s" character is successfully passed to the search API:

$(function() {
    $('.ui.product.search').dropdown({
    fullTextSearch: true,
    preserveHTML: false,
    debug: true,
    saveRemoteData: false,
    sortSelect: true,
    match: 'text',
    regExp: {
        escape: /[-[\]{}()*+?.,\\^$|#\s]/g,
    },
    apiSettings: {
        url: '/gpr/v1/product_codes/search?name={query}',
    },
 });
});

If you're receiving undefined results, it's possible that your search API is sending back data that Semantic UI cannot handle effectively.

Another potential issue could be interference from your Angular application. For example, if there are watchers on the model linked to the input field, changes to the input value might disrupt the behavior of the Semantic UI dropdown.

I recommend temporarily removing the ng-model directive attribute from the input to troubleshoot the dropdown search functionality. Once it's working correctly, reintroduce the model binding and proceed with debugging your Angular app.

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

Guide to displaying a task within a table cell after a user submits the form

<?php $servername = "localhost"; $username = "u749668864_PandaHost"; $password = "Effy1234"; $dbname = "u749668864_PandaHost"; $q = $_REQUEST["task"]; $task = $q; echo $task; $conn->close(); ?> Exploring the world of ajax has left me scratching ...

Is it possible to store data using kue in a node.js environment?

I am currently working with the kue and node.js framework. Check out kue on GitHub When I create and save a job, the data is stored in my local redis server. var job = queue.create('new_job', { title: 'welcome email for tj' ...

Add more functionality to the server.js script

I have the server.js file, which serves as the entry point for my Node application and is responsible for invoking three different functions (these functions are only called once when the server is up, such as creating child processes, validation, etc), wh ...

The process of computing and graphing an array based on a specific field

After creating a straightforward mongoose query to extract an array of data and sorting it, I received the following response: [ { _id: 60c3dce8f27cc56bbcf20e94, steamID: '76561199105033642', displayName: 'username', L ...

Determine the height of the left div, which is set to auto, and apply the same height to the right div, which has overflow set

I am facing an issue that needs a solution. I need to ensure that two div elements have the same height. The left div should have 'auto' height while the right one must match it. Moreover, the right div contains 14 nested divs that need to be scr ...

Encountered an error when attempting to load resource: net::ERR_CERT_AUTHORITY_INVALID following deployment on Vercel

I recently deployed a chatUI-app on Vercel that fetches chats from an API located at "http://3.111.128.67/assignment/chat?page=0" While the app worked perfectly in development, I encountered an issue after deploying it on Vercel where it ...

Incorporate the variables specified in the parent PHP file into the PHP code being received through

I am currently working on a project that involves enabling a user to view his profile upon login. However, I am aiming to have the dashboard load all other profile pages through ajax, such as the view profile and edit profile pages. My progress so far inc ...

Dynamic linked selection

Basic selection Segment Selection Category selection The choice of one parameter affects the options available in another section, with subjects depending on segments. If a subject is selected, only assignments related to that specific subject will b ...

What steps can be taken to prevent the "unable to convert undefined to an object" error from occurring?

There seems to be an issue with some of the documents not containing the planDetails and planId properties, resulting in the error "can't convert undefined to an object." However, I need to fetch that document whether these properties exist or not. Ho ...

When scrolling, numerous requests are sent to ajax - how can I consolidate them into a single request for lazy loading?

I encountered a problem where multiple Ajax requests are being sent when I try to call an Ajax function after scrolling. How can I resolve this issue? $(window).scroll(function(){ var element = $('.MainChatList'); var scrolled = false; ...

Retrieve weight measurements from a serial port by using Node JS

I'm a novice in node.js and I'm trying to retrieve weight data from a serial port. I have nodejs(v14.19.0) and npm(6.14.16) installed, and I'm attempting to obtain weight data using localhost:8080/get_weight. However, the script isn't f ...

Merging arrays of objects in JavaScript to create a fresh one

I am struggling to combine two sets of data into a single array by matching them based on the day. I want to create a new array of objects that include the relevant information from both sets. The first set includes the following: [ { date: '9/30/2 ...

Issue creating a JWT using jsonwebtoken module in Node.js

Could someone help me troubleshoot an issue I'm having while trying to generate a JWT token? The error message "TypeError: Right-hand side of 'instanceof' is not an object" keeps appearing even though the syntax seems correct. const jsonwebt ...

The jQuery function text().replace('','') is failing to work properly

After spending countless hours attempting to remove a text string that I previously appended, I am still struggling. The script I have is responsible for managing an accordion and unfortunately contains some redundant text. My goal is to add and remove th ...

Problem with AngularJS promise causing incorrect setting of 'this'

I am trying to populate a select list with data from a JSON file. Controller this.languages = []; var getData = $lcidFactory.obtainLCIDS(); getData.then( function(result){ this.languages = result.data; console.log(result.data); }, ...

"Encountering issues with the construction of a Heroku application generated using the angular

After successfully building my app with sudo grunt build and serving it using sudo grunt serve:dist, I encountered an issue when trying to deploy to Heroku using yo angular-fullstack:heroku from the project root for the first time. The deployment process ...

What steps should be taken to address the Chrome alert stating that the deferred DOM Node cannot be identified as a valid node?

While working on my node.js project hosted on a localhost server, I've encountered an unusual warning message in the inspector. The warning states: The deferred DOM Node could not be resolved to a valid node. Typically, I use the inspector to examine ...

Guide on utilizing Vue to trigger an API call when the input box loses focus

I am currently facing challenges while trying to learn vue, and I am not sure how to proceed. I would greatly appreciate any assistance! To begin with, I want to acknowledge that my English may not be perfect, but I will do my best to explain my issue tho ...

Exploring OOP Strategies within the Angular MVC Framework!

After coming across a question on Stack Overflow that was similar to mine, I realized I have a lot to learn about Object-Oriented Programming (OOP). Up until now, my coding experience has been mainly procedural. Before diving into my question, let me provi ...

Vue - Triggering @change event for file input element when files are set programmatically using ref instead of drag and drop upload

My setup includes a file input for drag and drop image uploads. <input type="file" ref="FileInput" style="display: none;" @change="onFileSelect" accept=". ...