6

I'm extremely new to javascript and dat.gui so bear with me. I'm wondering how to create a drop down menu with a default value at the top:

so i have something like:

gui.add(text, 'language', ['english','spanish','french']);

How could I make that drop down say something like "Select Language" by default before actually selecting a value?

thanks!

Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
DSquad
  • 101
  • 5

2 Answers2

4

After struggling a lot with a similar problem, I can tell you that I have no idea how to do specifically what you ask for with dat.GUI . However, you can select a default value like this:

let dropdown = gui.add(text, 'language', ['english','spanish','french']);
dropdown.setValue("french"); // cuz I like french better

I know this is an old question, but I hope it helps someone out there XD

Edit: you could also chain it all together :P

gui.add(text, “language”, [“english”, “spanish”, “french”]).setValue(“french”);
Jaacko Torus
  • 796
  • 7
  • 24
0

I did this

initialization with option 'spanish' or another valid option, if the option doesn't exist it will fail

gui.add(text, 'language', ['english','spanish','french']);

text.language = 'spanish'; 
updateDisplay(gui);

updateDisplay = function(gui) {
    for (var i in gui.__controllers) {
        gui.__controllers[i].updateDisplay();
    }
    for (var f in gui.__folders) {
        SCENE.updateDisplay(gui.__folders[f]);
    }`enter code here`
};
  • Hey, I know this is a relatively old answer, but I just don't get what you're writing here, I'm having this same problem and I even tried to modify dat.gui.js (obviously with no success). Could you please explain further? – Jaacko Torus Jul 04 '19 at 19:08