1

I'm developing a sketch plugin. In the modal window I'm using to get user input there is a select. I can access the value of textField but I can't access value of the select.

Here is where I create the select:

var chooseFormatOptions = ['.png', '.jpg', '.pdf'];
var chooseFormatSelect  = NSComboBox.alloc().initWithFrame(NSMakeRect(0, 250, viewWidth, 30));
chooseFormatSelect.addItemsWithObjectValues(chooseFormatOptions);

Here is where I try to get the combo box value

 if (response  == "1000"){
        var projectName = projectField.stringValue();
        var deviceName1 = firstDevicefield.stringValue();
        var deviceDim1 = firstDimfield.stringValue();
        var deviceName2 = secondDevicefield.stringValue();
        var deviceDim2 = secondDimfield.stringValue();
        var format = chooseFormatSelect.objectValues.indexOfSelectedItem(),
        //var scale = chooseScaleOptions.stringValue();
        //var pathOption = choosePathOptions.stringValue();
      }

The error that it gives me when I run the plugin (if response == 1000) is: can't find variable chooseFormatSelect.

Do you know why I can get values of input fields (so it can find variables) but not that of the select one?

Matteo Vacca
  • 113
  • 3

1 Answers1

-1

What about access text field 'text' variable while observing changes?

You may find this link helpfull (to add observe).

For NSComboBox follow this

Simply implement delegate then access value through following method

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
  • I don't have any problems with textField. I can easily access to its value calling nameField.stringvalue(). But this doesn't work for select box. The debugger tells me that it can't find the variable, even if it can find the variable which contains the value of textField. Both are in the same function. Why it can access to the first and not to the other one? – Matteo Vacca May 31 '17 at 10:30
  • @MatteoVacca add observer and save value that you want to any variable. I'm not understand what value you talking about, if you using text field the only variable is changing is textField.text – Evgeniy Kleban May 31 '17 at 10:32
  • I don't understand why using an observer. I try to be more clear: I have several input fields in an alert view and one combobox. From the main function I call the function to create the layout of the modal view where I put input fields and combo box. From the main I can access to values of input field (so if user type in the input I can get its value) but I can't access to the selected item in the combo box. I can't understand why. – Matteo Vacca May 31 '17 at 10:38
  • @MatteoVacca check you code and verify that your delegate methods work then. – Evgeniy Kleban May 31 '17 at 10:51