Issues with Laravel 5.8 and Bootstrap not functioning properly in Jquery

Check out this link for using Bootstrap Select. The code works perfectly in the view, but when I try to implement it with jQuery below, it doesn't work. Can someone help me fix this issue?

View Code:

<table id="tableAppointment" style="background-color:powderblue;">
     
    <tr>
        <th style="text-align:center;" colspan="1">NAME</th>
        <th style="text-align:center;" colspan="1">HSN/SAC</th>

        <th><a href="#" class="addRow btn btn-warning vertical-center"><i class="glyphicon glyphicon-plus">ADD</i></a></th>
    </tr>

    <tr>
        <td>
            <select class="selectpicker" data-live-search="true"  name="product_name[]">
               <option value=""></option>
                @foreach ($addnewitem as $key=>$addnewitems)
                    <option>{{$addnewitems->product_name}}</option> 
                @endforeach
            </select>
        </td>

        <td>
            <select class="selectpicker" data-live-search="true"  name="part_no[]">
                <option value=""></option>
                @foreach ($addnewitem as $key=>$addnewitems)
                    <option>{{$addnewitems->part_no}}</option> 
                @endforeach
            </select>
        </td>

        <td><a href="#" class="btn btn-danger "><i class="glyphicon glyphicon-remove">REMOVE</i></a></td>
    </tr>

</table>

<script type="text/javascript">

    $('.addRow').on('click',function(){
        addRow();
    });
    
    function addRow()
    {
    
        var tr = '<tr>' + '<td><select class="selectpicker" data-live-search="true"  name="product_name[]"><option value=""></option> @foreach ($addnewitem as $key=>$addnewitems)<option>{{$addnewitems->product_name}}</option>@endforeach </select></td>' + '<td><select class="selectpicker" data-live-search="true"  name="part_no[]"><option value=""></option> @foreach ($addnewitem as $key=>$addnewitems)<option>{{$addnewitems->part_no}}</option>@endforeach </select></td>' + '<td><a href="#" class="btn btn-danger remove"><i class="glyphicon glyphicon-remove">REMOVE</i></a></td>' + '</tr>';
        
        $('tbody').append(tr);
    };
    
    $('.remove').live('click', function(){
        var last = $('tbody tr').length;
        if(last == 1){
            alert("You can not remove the last row");
        } else {
            $(this).parent().parent().remove();
        }
    
    });

</script>

Answer №1

When you click on $('.addRow'), make sure to refresh the selectpicker

If you need to update the bootstrap-select user interface after making changes to underlying values that impact the layout, you can use the render method.

$(document).on('click','.addRow',function(){
    addRow();
    $('.selectpicker').selectpicker('refresh');

});

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

Switching between dark and light mode in Ant Design

I have successfully implemented dark mode toggling in my application. However, when I try to switch back to light mode, the CSS does not seem to be reloading properly. Below is the code snippet: //ThemeContext.jsx const DarkTheme = lazy(() => import(". ...

Who needs a proper naming convention when things are working just fine? What's the point of conventions if they don't improve functionality?

I am a newcomer to the world of JavaScript programming and stumbled upon this example while practicing. <html> <head> <script type="text/javascript"> function changeTabIndex() { document.getElementById('1').tabIndex="3" d ...

Learn how to utilize AngularJS Material to toggle the enable/disable functionality of a checkbox

Can someone assist me in enabling and disabling the checkbox as shown in the attachment image https://i.stack.imgur.com/l6g1C.jpg View the PLNKR angular.module('BlankApp', ['ngMaterial']) .config(['$mdThemingProvider', fun ...

`Using a Video in a JQuery Carousel`

Currently in the early stages of developing a JQuery Slider that will kick off with a video, transitioning into slideshow mode once the video concludes. My goal is to ensure compatibility with IE9 and lower, as well as iPhone devices, necessitating options ...

Automatically adjusting the top margin of the main content section depending on the variable height of a fixed header

Visit our mobile site here (mobile view) Currently, I have set the margin-top of .main-content based on sticky-animation, which keeps the header fixed at the top on mobile. However, there is a div with a close button (X) that alters its height dynamically ...

Managing job queues with multiple providers in Laravel

I have implemented Redis for caching dispatched jobs in my API controllers. Here is an example of how one of my controllers looks: class FormSubmissionsController extends Controller { /** * @param StoreRequest $request * @return \Illumi ...

JQuery function fails to execute upon first page load

I am currently facing a situation where I need to wait for a specific image to load before either swapping out its src or showing/hiding the next image. The desired outcome is to display a placeholder image (silhouette) until the main image loads, then hi ...

Activate the child for an update

Welcome! I am a newcomer to Angular and would greatly appreciate any assistance. The parent component of my picker has the ability to create various rules for each option. However, these rules are dynamic and can change frequently. I need to ensure that ...

Replace the default focus state using CSS or resetting it to a custom style

I'm looking for a solution similar to a CSS reset, but specifically for the :focus state. If such a thing doesn't exist yet, I'm interested in learning about the possible properties that can be reset or overridden in order to create a new :f ...

Tips for positioning icons inserted using the :before method

Is there a way to center align an icon added using the :before method? Below is the current code snippet: <div class="button submit"> <a class="submit check_car_search" href="#" >Some Text</a> </div> CSS: .button a{ backgr ...

"Kindly complete all mandatory fields" - The undisclosed field is preventing me from submitting

I am facing an issue with my WordPress page that has Buddyboss installed along with Elementor pro as the Pagebuilder. The Buddyboss plugin provides Facebook-like functions on the website. While it is easy to comment on posts within the Buddy Boss system, I ...

Troubleshooting Vue.js and Laravel: Having trouble loading new image files, while the older ones load just fine

Currently, I am working on a project that involves Vue.js and Laravel. In this setup, Vue is located inside the resources/js directory of the Laravel project. My current issue revolves around loading an image from the resources/js/assets directory. While ...

Javascript clock problem, kick off on click

Currently working on a game and in need of a counter that starts when clicked and stops at 00 (From 1m to 00). It is currently starting onload and cycles back to start when it reaches 00. HTML: <body> <div> <div class="timer" >Battle t ...

Defining variables within a jQuery function

Within my initialization function (init), I have defined some variables and an animation that utilizes those variables. The challenge arises when I want to use the same animation/variables in my clickSlide function. http://jsfiddle.net/lollero/4WfZa/ (Un ...

What is the best way to make this eerie javascript script communicate with my webpage or another jquery file?

I've been struggling with a javascript code that enables infinite scrolling in Tumblr. It seems outdated compared to jQuery, which I'm more familiar with. I've tried integrating this script with my jQuery functions and identifying DOM eleme ...

The onclick handler fails to function following the injection of html using jquery AJAX

After using ajax to inject HTML into my page, the onclick handler on a specific part of that injected HTML does not seem to be functioning... Specifically, I am referring to this image... < img class="close_row" src="img/close.gif"/> In jQuery, I ...

Placing a new item following the child of a different element

How can I use jQuery to add a div inside id123 after sth2, but only for one specific occurrence? I understand how to do it after every sth2, but not just once. <div class="id123"> <div class="a"></div> .. <div class="sth1">< ...

The initial ajax request successfully connects to the file, but encounters a 404 error upon the second attempt

I am currently encountering an issue with a jQuery post function. The function is designed to run multiple times and then stop, which it has successfully done in the past. However, now the problem arises when the function tries to execute itself again afte ...

Exploring the Benefits of Using JSON in AJAX Requests

Can you help me determine the best way to extract data from a php page using ajax in the form of a json array? Here is an example code snippet: $.ajax({ type: "get", url: "assets/update_cart_user_fstore.php", data: up, cache: false, su ...

My PHP script is not functioning correctly with Ajax

I am currently working with HTML5, PHP, and JavaScript. My goal is to implement Ajax in order to display the sizes of a selected product when an option is chosen from #productoSeleccionado. However, I believe that there may be an issue with my code as the ...