I am trying to figure out if it's possible to update just the dropdown list values for a dat.gui controller.
var gui = new dat.GUI();
gui.add(this, 'toggle').onChange( updateToggle );
gui.add(item, 'template', [ 'A', 'B', 'C', 'D' ]).onChange( updateTemplate );
When the toggle is changed, i want to modify the template options:
if (startRibbon) {
gui.__controllers[1].options(['A', 'B']);
} else {
gui.__controllers[1].options(['A', 'B', 'C', 'D']);
};
This does change the values, but it creates a new template controller with a new index (deleting the previous one) and making it not work the next time. It also pushes the new one to the bottom of the controller list.
Before I add more code to try and chase after the new modified/new controller, I figured I should see if anybody has a better way.
I was trying to do the same thing. My solution is to use the onChange to remove and add the controller. Because it pushes it to the bottom and messes up the order, I cannot just do what you did directly. I also have to remove and add back in seq all those that are below it.
Or if there are too many controllers, it would be more convenient to just have a function to remove all and add all back for such cases.
Editing my solution for your example, it will be something like this...