MechMK1
MechMK1

Reputation: 3378

How to get/set text values in widgets?

I'm fairly new to working with OS X widgets and wanted to create a simple widget for myself which should simply get the stringValue of a textbox, add it to a fixed string and open this in a browser.

I already figured out the last part can be done with widget.openURL(string) but the rest is too confusing for me. I could not find any usefull code completion, neither did my experience in Obj-C or any other language help a bit.

Upvotes: 0

Views: 390

Answers (1)

Jason
Jason

Reputation: 1632

To retrieve the value once you have the textbox part, you just get its value member: textBox.value.

For example, you can search the DOM for the element by the ID which you set for the textbox in the Dashcode Inspector.

var textBox = document.getElementById("myTextBoxId");
var theString = textBox.value;

If your text box is editable, you can just set the value.

textBox.value = "Some new string";

To set the value for text parts which aren't editable like buttons or labels, set the innerText of the part.

textBox.innerText = "Some new string";

Upvotes: 1

Related Questions