Git Product home page Git Product logo

Comments (2)

alexandru-paduraru avatar alexandru-paduraru commented on May 9, 2024

@juliocast thank you for pointing that out. It seems the issue is coming from how we handle the sidebar on mobile. We basically move anything out of the navbar and add it to the sidebar for mobile. You can see the code in material-dashboard.js starting with line 117:

if(!mobile_menu_initialized){
            $navbar = $('nav').find('.navbar-collapse').first().clone(true);

            nav_content = '';
            mobile_menu_content = '';

            $navbar.children('ul').each(function(){

                content_buff = $(this).html();
                nav_content = nav_content + content_buff;
            });

            nav_content = '<ul class="nav nav-mobile-menu">' + nav_content + '</ul>';

            $navbar_form = $('nav').find('.navbar-form').clone(true);

            $sidebar_nav = $sidebar_wrapper.find(' > .nav');

            // insert the navbar form before the sidebar list
            $nav_content = $(nav_content);
            $nav_content.insertBefore($sidebar_nav);
            $navbar_form.insertBefore($nav_content);

            $(".sidebar-wrapper .dropdown .dropdown-menu > li > a").click(function(event) {
                event.stopPropagation();

            });

            mobile_menu_initialized = true;

Basically, we move the search using the clone, that means it is losing all the JS properties. Maybe you can add the clone(true,true) as presented here: https://stackoverflow.com/questions/9549643/jquery-clone-not-cloning-event-bindings-even-with-on

I will do some further checks with my colleague @dragosct10 and come back with a solution on Monday/Tuesday.

Keep in touch,
Alex

from material-dashboard.

juliocast avatar juliocast commented on May 9, 2024

Hi Alex!

Thank you very much for explaining. I could solve the issue but I may have overcomplicated it.
I added the mask setting in the file too and it solved the mask issue.

        mobile_menu_initialized = true;

        // Plate mask for search field
        $('#plate-search-field').mask('SSS0000');

Now for the form handling what I did is the following:

        // Form submit event listener and handler
        document.addEventListener('submit', eventHandler);

        function eventHandler(e) {
            e.preventDefault();
            let sourceFormId = e.srcElement.id;

            if (sourceFormId === 'plate-search-form') {
                let plate = e.target["0"].value;
                searchPlate(plate);
            }
        }

I'm looking for submit events and checking the source element ID, this way I can have as many forms as I want and just treat them by their IDs.

One thing I wanted to point too is that there is one doubled menu item within the mobile view sidebar:
image
I understand that this happens because all of the desktop search menu is put within the sidebar.
image

I think I can hide the second one and give an "active" class to the first one, right?

Thank you very much!

from material-dashboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.