Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Nestable.js issue with callback updating textarea

I'm having an issue with nestable.js and maybe I'm using the callback incorrectly. Below is my current code and I'm loading the JSON from the php variable $primary_menu_json that is passed into the function. It creates the menu with no issues and I can move my menu elements around that are created from the JSON no problem, but it's not updating my hidden textarea (#nestableOutput) on the callback.

The way I understand the callback from the documentation is it's fired when elements are reordered or nested. In my mind this would be the place to update the hidden textarea when an element is dropped. Maybe I am wrong in this thinking. Any help?

    $(document).ready(function () {

        function nestableJSON(jsonArray, root) {

            if (typeof root === 'undefined') {
                root = $('body');
            }
            var $div = $('<div id="nestable02a" class="dd" data-plugin="nestable"><ol class="dd-list dd3-list"></ol></div>');
            root.append($div);

            for(var i = 0; i < jsonArray.length; i++) {
                var $li = $("<li class='dd-item dd-item-alt' id='item-" + jsonArray[i].id + "' data-id='" + jsonArray[i].id + "' data-title='" + jsonArray[i].title + "'><div class='dd-handle'></div><div class='dd-content'>" + jsonArray[i].title + "<span class='float-right wb-trash'></span></div></li>");
                root.find('ol.dd-list:first').append($li);

                if (typeof jsonArray[i].children !== 'undefined') {
                    nestableJSON(jsonArray[i].children, $li);
                }
            }

            $('#nestable02a').nestable({
                group: 1,
                maxDepth: 3,
                callback: function(e){
                    var list = e.length ? e : $(e.target);
                    $('#nestableOutput').text(window.JSON.stringify(list.nestable('serialize')));
                    console.log('json updated');
                }
            });

        }
        nestableJSON(<?php echo $primary_menu_json; ?>);
    });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!