How do I get a form list "value", not the "text?

Get help using Construct 2

Post » Tue Mar 17, 2015 12:11 pm

I have some form List controls. They have items with "values" (database _id's) as well as "text". It's clear how to get the text but how do I get the _id's stored in the item values?
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Tue Mar 17, 2015 12:36 pm

There is nothing can stop you from using int() function.
Code: Select all
a = 0 //numeric var
s = '5552368' //string var
a = int(s); // a = 5552368

beware:
a = 100
s = 'text'
a = int(s) // a = 0


And now I read your question more attentively.. I understand, you want an Index of selected item in List plugin? It is List.SelectedIndex expression.
B
8
Posts: 72
Reputation: 456

Post » Tue Mar 17, 2015 1:05 pm

No, I want to get the "value" in the "Select" control on the form. In the Html the select control looks like...

Code: Select all
<select>
<option value="someDbaseId">Marks name text</option>
</select>


I can see in C2 List control how to get the text of the option (item), but not the value. Follow?
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Tue Mar 17, 2015 1:37 pm

Sorry, man.. I don't even know how to do what you knows..
B
8
Posts: 72
Reputation: 456

Post » Tue Mar 17, 2015 1:41 pm

NickRimer wrote:Sorry, man.. I don't even know how to do what you knows..


No problem :-)

I've hacked around the issue with a couple functions wrapping an array. However I'd greatly prefer using a built in solution :?
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Tue Mar 17, 2015 11:01 pm

So other than my hack mentioned above, this isn't possible in C2?
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Fri Mar 20, 2015 4:30 pm

You can get form control List "Text" values easily but there is no C2 built-in way to get a List "Value"?!?

So... this is a feature or omission? :shock: :?
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Fri Mar 20, 2015 7:27 pm

I think C2 just uses the index and not a value for the list items.

Looks like best you can do is get the index number of a selected text.

The work around would be to have the values associated with the list items stored and referenced to from somewhere else. (local vars, globals, instance vars)
You could even use the instance vars from the list itself.
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,867

Post » Fri Mar 20, 2015 8:07 pm

Right now I have some functions that I use to set the Text attribs in the Lists objects and at the same time set an associated Value in an array. It's pretty amazing that there isn't a built in way to get the List.SelectedItemValue too. I'd love to know why not :(
B
13
S
4
Posts: 280
Reputation: 1,566

Post » Fri Mar 20, 2015 8:20 pm

Its likely an easy addition to the existing code, you could request for it perhaps.

Perhaps it has to do with that a lot of web developers use the text as value.
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,867


Return to How do I....?

Who is online

Users browsing this forum: mystazsea, Zebbi and 20 guests