Issue with jQuery select box (roblaplaca) and its custom scroll bar functionality not functioning as expected

Recently, I implemented the custom select box script from . This script allows for two select boxes, where the second one updates dynamically using AJAX when there is a change in the first select box. Below is a sample of the HTML code:

<option>One</option>
<option>Two</option>
<option>Three</option>

To update my select box after an AJAX success, I utilized the sync() method. While the content does get updated successfully, I encountered an issue where the scroll bar disappears.

I delved into the selectbox.js file and noticed that the sync() method invokes the _setupScrollbar() function after updating the content. However, despite this call, the scroll bar fails to appear. Can anyone provide assistance with resolving this problem?

If you want to explore the code further, feel free to check out the Demo code.

Answer №1

When working with your SelectBox.js file, make sure to make the following modifications:

(1) Locate the function _setupScrollbar() and insert the code autoReinitialise: true. The updated code should appear as follows:

self.scrollpane = $dl.jScrollPane($.extend({
    contentWidth: 200,
    autoReinitialise: true
}, cfg.scrollOptions));

(2) Find the function this.sync = function() and make the following changes:

this.sync = function() {
    $options = cfg.selectbox.find("option");
    //$dl.html(_renderOptions());
    $jpane = $customSelect.find("div.jspPane");

    if($jpane.length == 1) // check if selectbox has a scrollbar
    {
       $jpane.html(_renderOptions()); //Inject HTML into selectbox with scrollbar
    }
    else
    {
       $dl.html(_renderOptions()); //Inject HTML into selectbox without scrollbar
    }

    _bindHover();
    _setupScrollbar();
};

The scrollbar may not be functioning due to jsPane being replaced with new content. Therefore, I have made adjustments in the sync() function as shown below:

// $dl.html(_renderOptions());
$jpane = $customSelect.find("div.jspPane");
if($jpane.length == 1) // need to check if selectbox having scroll bar?
{
   $jpane.html(_renderOptions()); //HTML injected to selectbox having scrollbar
}
else
{
   $dl.html(_renderOptions()); //else HTML injected to selectbox not having scrollbar
}

These changes should help resolve the issue you are facing.

Answer №2

I made some changes to @rajnikanth's code for customizing a selectbox without a scroll bar.

this.update = function() {
    $optionsList = cfg.selectbox.find("option");
    //$dl.html(_renderOptions());
    $scrollPane = $customSelect.find("div.scrollPane");

    if($scrollPane.length == 1) // check if selectbox has a scroll bar
    {
       $scrollPane.html(_renderOptions()); // Inject HTML for selectbox with scrollbar
    }
    else
    {
       $dl.html(_renderOptions()); // Inject HTML for selectbox without scrollbar
    }

    _bindHover();
    _configureScrollbar();
};

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

Tips for preventing duplication of business logic across client and server side code?

Over time, I have been developing more API-driven web applications to meet the growing needs of web apps. Using frameworks like AngularJS, I create advanced web clients that interact with these APIs. Currently, my server side/API is built using PHP (Lumen ...

Having trouble with the dropdown onclick event not triggering when an item is selected in React?

I am having an issue where the onclick event handler is not being called when a dropdown item is selected. In my code, I am generating a dropdown inside a loop in the componentDidMount() lifecycle method. I am passing an event handler function named "show ...

Loading bar as data makes its way from Excel spreadsheet to SQL database table

Is there a way to display an animated progress bar while transferring data from an Excel sheet to a SQL database table? I have a form on my .aspx page that includes a FileUpload control for uploading Excel files. As the file is being uploaded and saved on ...

Leveraging personalized data-* attributes within the <template> tag in HTML5

I am currently developing a menu using a dom-repeat template as shown below: <template is="dom-repeat" items="{{appletsMenu}}"> <a data-route="{{item.dataRoute}}" href="{{item.href}}"> <iron-icon icon=" ...

Tips for merging two classes in CSS

Within my code, I have two classes named classA and classB. I am looking to have classB inherit the style of classA while still only using classB. .classA{ width:100px;} .classB{ height:100px;} <div class="classB"></div> ...

Add elements to an array following an AJAX request

On my .cshtml page, I have the following script: $(function () { var tempArray = []; var tbValue = $('#tb1').val(); $.ajax({ url: "/ControllerName/getdata", dataType: 'json', ...

Bootstrap5: Left-aligned Navigation Bar Pills and Right-aligned Text

I am trying to align all my navigation pills to the left, and then add a single text element that stays at the end of the navbar even when the page is resized. Navbar Image My attempt involved adding a div so that the navbar pills would take up 50% width ...

Updating existing text to create personalized HTML dropdown menus

I have designed a unique set of dropdowns by using divs and checkboxes instead of the traditional elements My goal is to dynamically change the 'select-wrapper--title' text (e.g. the first option) based on the selected option in the dropdown I ...

Utilizing Jquery: Extracting the value of a child element upon clicking the encompassing parent div

I've created a table-like structure using divs instead of tables (because I strongly dislike tables). However, I'm facing an issue. I want to be able to click on one of the div elements and extract the values of its child elements. <div cla ...

Creating a circular array of raycast directions with HTML Canvas 2D

I'm currently working on implementing raycasting in typescript with HTML Canvas 2D based on the tutorial from this video: https://youtu.be/TOEi6T2mtHo. However, I've encountered an issue where the rays being cast consistently point in a single di ...

HTML is being incorrectly rendered by the Express framework

Looking to Use HTML as View Engine in Express? After going through the link, I attempted to start my server with an index.html file on port 8001. However, it failed to render correctly and showed an error in the console: Server Started Error: SyntaxError ...

Encountering an error in Selenium Python when using the second iteration of find_elements_by_xpath

I'm currently navigating through my college website dashboard to find all relevant subjects. I am utilizing selenium for this task. Due to the slowness of the site, I implement a waiting period. WebDriverWait(driver, 20).until(EC.element_to_be_clickab ...

Foundation 5 - ensure background-image covers the entire column width

I'm trying to achieve a unique layout using Zurb Foundation. My goal is to have two columns, each taking up half of the screen: <div class="small-6 columns"><!-- INSERT IMAGE HERE --></div> <div class="small-6 columns"> < ...

Cannot trigger event ascn.onchange does not exist as a function

Need to trigger the onChange function and pass parameters within it. Here's what I have tried: setTimeout(function() { document.getElementById(input.key)?.onchange({}) }, 200); Encountering the following error message: cn.onchange is not a function ...

React is having trouble rendering the current weather information

My code is not functioning properly and I am encountering a TypeError that says "cannot read the property of undefined ('temp')". import React, { useEffect, useState } from "react"; import "./css/style.css"; import { BiStreetV ...

Extracting elements from a dynamic website within the <script> tag using the libraries BeautifulSoup and Selenium

I am currently working on scraping a dynamic website using beautifulsoup and selenium. The specific attributes I need to filter and export into a CSV are all located within a <script> tag. My goal is to extract the information found in this script: ...

What is the syntax for accessing a dictionary item within a <span> tag using JavaScript?

I'm working on a new functionality for a website that involves using a dictionary to store information about clubs, events, and times. var clubName = {}; var event = {}; var time = {}; var dict = new Map(); dict.set(clubName, "G ...

Prevent the Rain from descending

Looking for a way to toggle a particle emitter on or off, I've encountered memory leaks with my Reactjs code that generates rain/snow particles using the canvas element. Despite attempts to stop the animation properly, it seems to be projecting a new ...

Issue encountered while transferring files between a web platform and an API

Currently, I am working on two separate projects. The first project involves a website where users can upload files, and the second project is an API designed for file uploads due to the limitations of the old website. I am utilizing Laravel (6) to develo ...

I'm struggling to understand the purpose of using response.on

I have a code snippet here and I am curious about the functionality of "response.on" and why we are passing "data". What does this "data" represent? Also, could you explain what ".on" is specifically used for in this context? const express = require("exp ...