SID-01605: Recording or looking up corresponding values
| Status: |
Answered |
TWiki version: |
5.0.2 |
Perl version: |
|
| Category: |
CategoryForms |
Server OS: |
|
Last update: |
13 years ago |
I have a form with a select field. The field has user-friendly names. I need to frequently use a corresponding user-unfriendly value. There is a 1:1 relationship between the user-friendly name and user-unfriendly value.
This problem is similar to a DNS lookup. A user selects a host name and that domain name has an associated IP address.
Ideally, I would like to allow the user to select the friendly name from a select list in the form and store in addition the corresponding user-unfriendly value, but I could perform a lookup at use as long as the lookup wasn't too much more difficult than using a formfield.
The relationship between name and value is static and could be defined in a table somewhere.
Any pointers?
--
JoshuaTharp - 2012-12-06
Discussion and Answer
Not sure if applicable in your case, but I sometimes use a dynamic lookup for select option display values. Say, options are unreadable topic names, and you have a nice name in a form field named "Title" of those topics.
Example:
%CALCULATE{$SET(requirements, %SEARCH{....}%)}%
<select name="Requirement" class="twikiSelect" id="idRequirement">
<option></option>
%CALCULATE{$LISTJOIN($sp, $LISTMAP(<option value='$item'>$NOP(%)FORMFIELD{ "Title" topic="$item" }$NOP(%)</option>, , $GET(requirements)))}%
</select>
--
PeterThoeny - 2012-12-06
Or, you could take the unreadable name and space it out using a similar CALCULATE as the one above.
--
PeterThoeny - 2012-12-06
You are doing some advanced TWiki stuff. How about writing a case study blog on TWiki.org how TWiki helped your organization support and enhance your processes? See
BlogIdeas and read some existing blogs for inspiration, like the one of Morgan Stanley, CERN and Aseaco.
--
PeterThoeny - 2012-12-06
OK, I can see how I would use your suggestion to populate a custom HTML form for creating topics. The select box would contain a list of the Title form fields from your search criteria (or my user-friendly name), and the passed value would be the topic name (or my user-unfriendly value). The result is that the created topic form would have the unfriendly value.
Another thought I had - so that I could just use the TWiki forms - was to combine the friendly name and unfriendly value (
name (value)). I could get either the name or the value that way but at the cost of having to parse the formfield in order to use it.
--
JoshuaTharp - 2012-12-07
I have some concrete ideas how to enhance TWiki forms with a select that supports a nice label for options:
Form definition:
| Field_Name |
select+label |
1 |
A: Label for A, B: Label for B, C: This is C |
|
|
And SEARCH format:
-
$formfield(Field_Name) - returns value "A" if A was selected
-
$formfield(Field_Name, label) - returns label "Label for A" if A was selected
And
QuerySearch:
-
Field_Name='A' - test form field for value "A"
-
Field_Name.label='Label for A' - test form field for label of value "A"
Feel free to submit a feature proposal and implement it. Or, hire a TWiki consultant to do that for you.
--
PeterThoeny - 2012-12-08
I like it. I would add that in the form view on the topic, both the label and the value should be displayed.
--
JoshuaTharp - 2012-12-10
Funny, I forgot that this feature already exists:
TWikiForms
--
PeterThoeny - 2012-12-11
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.