Tags:
create new tag
, view all tags

Question

I got the following from pattern 1 of SearchPatternCookbook.

Pattern 1: Extract values from a table

Problem definition

Suppose there is a topic with a table defining entries in a TWikiForm. I.e. they define select menu items in a form template. They are then formatted like:

| *Name* | *Type* | *Tooltip message* |
| option1 | option | |
| option2 | option | |
| option3 | option | |

How to extract the 'name' values, i.e. 'option1', 'option2' and 'option3' and put them in a HTML form select input?

Solution

The following search pattern can be employed:

<form>
<select>
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
</select>
</form>

which is, in effect:

My Concern

So far, so good, but the problem shows when the same search is applied in another table. The row where the above search is applied is not properly rendered by the table.

<form>
| *Name* | <input type="text" size="20" /> |
| *Option* | <select>
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
</select> |
</form>

which is, in effect:

Name
| Option | |

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Search

-- FredanLangam - 14 Nov 2007

Answer

ALERT! 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.

I got it. Just put <select>, %SEARCH% and </select> together in one line and add separator="" for the SEARCH.

<form>
| *Name* | <input type="text" size="20" /> |
| *Option* | <select>%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" separator="<nop>"}%</select> |
</form>

which is, in effect:

Name
Option

-- FredanLangam - 14 Nov 2007

Change status to:
Topic revision: r1 - 2007-11-14 - FredanLangam
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.