autocomplete type to TWikiForms:
| Type | Description | Size | Value |
|---|---|---|---|
autocomplete |
Autocomplete input field. Start typing to get a list of items to choose from, or click on the pulldown button to see all items. |
Size of input field in number of characters | Comma-space separated list of autocomplete options |
autocomplete+restrict |
Autocomplete, where input is restricted to list of autocomplete options. The value in the input field will be cleared if it does not match one of the autocomplete options. Partial input is expanded - for example if one of the options is "JavaScript" and the user typed "ja", the input field is expanded to "JavaScript" on focus loss. | ||
autocomplete+values |
Like autocomplete, allowing definition of inserted values that are different to the displayed autocomplete options. An autocomplete option is defined as value: title, where the value is the text inserted into the input field when picking the title option. For example:| Field 9 | autocomplete+values | 3 | One, 2: Two, III: Three | Various values formats | shows autocomplete options but the inserted values of autocomplete options Two and Three are 2 and III, respectively. Note: Autocomplete types can be combined: autocomplete+restrict+values |
||
M (for mandatory fields), and H (for hidden fields) are supported. In addition, the key="value" parameters of the AUTOCOMPLETE variable can be specified as well, such as style="color: blue;". If combined, the key="value" parameters must be specified after the M and H attributes.
Example form definition:
| Name: | Type: | Size | Values: | Tooltip message: | Attributes: |
|---|---|---|---|---|---|
| Marital Status | autocomplete+restrict | 50 | Single, Engaged, Married, It's complicated, Divorced | Specify marital status | M style="color: blue;" |
<form action="...">
%AUTOCOMPLETE{ name="Mood" value="Indifferent" options="Happy, Indifferent, Confused, Unhappy, Angry" size="10" }%
<form>
This will show an HTML input field named "Mood" and an autocomplete pulldown when typing.
| Parameter | Description | Default | Example |
|---|---|---|---|
name |
Name of input field | (required) | name="Mood" |
value |
Form field value | "" |
value="Happy" |
options |
Comma-space separated list of autocomplete options. Example options when type="values" is used: options="1: One, 2: Two, 3: Three" - when a user picks option Three, the input field will have text 3 inserted. |
"" |
options="Happy, Indifferent, Sad" |
size |
Size of input field, in number of characters | "40" |
size="20" |
type |
Types of autocomplete: • type="" (empty): Simple autocomplete • type="restrict": Restrict input to list of autocomplete options. The value in the input field will be cleared if it does not match one of the autocomplete options. Partial input is expanded - for example if one of the options is "JavaScript" and the user typed "ja", the input field is expanded to "JavaScript" on focus loss. • type="values": Define inserted values that are different to the displayed autocomplete options. An autocomplete option is defined as value: title, where the value is the text inserted into the input field when picking the title option. • type="restrict, values": Types of autocomplete can be combined. |
"" |
type="restrict" |
id |
ID of input field | (none) | id="mood" |
class |
Add additional class(es) to input field, default is "twikiInputField twikiEditFormTextField autocompleteTextField" |
"" |
class="myClass" |
style |
Add CSS to input field. A width: num; is already added, where num is calculated from the size parameter; the width can be overloaded. |
"" |
style="color: blue;" |
selectstyle |
CSS of select element | "" |
selectstyle="color: blue;" |
containerstyle |
CSS of autocomplete container div | "" |
containerstyle="font-size: 90%;" |
| ... | Additional HTML 4 and HTML 5 attributes can be specified for the input field: formname, maxlength, onblur, onfocus, onchange, onselect, onmouseover, onmouseout, pattern, placeholder, spellcheck, tabindex, title |
placeholder="How do you feel?" |
AutocompletePlugin.zip in your twiki installation directory. Content: | File: | Description: |
|---|---|
data/TWiki/AutocompletePlugin.txt | Plugin topic |
data/TWiki/VarAUTOCOMPLETE.txt | Variable documentation topic |
pub/TWiki/AutocompletePlugin/*.gif and *.png | Image files |
lib/TWiki/Plugins/AutocompletePlugin.pm | Plugin Perl module |
lib/TWiki/Form.pm:
--- lib/TWiki/Form.pm (revision 28279)
+++ lib/TWiki/Form.pm (working copy)
@@ -220,7 +220,10 @@
# Returns array of arrays
# 1st - list fields
# 2nd - name, title, type, size, vals, tooltip, attributes
-# Possible attributes are "M" (mandatory field)
+# Possible attributes are:
+# "M" (mandatory field - DEPRECATED - now mandatory="1"),
+# "H" (hidden field - DEPRECATED - now hidden="1"),
+# followed by type-specific name="value" configuration pairs
sub _parseFormDefinition {
my( $this, $meta, $text, $options ) = @_;
$options ||= {};
@@ -279,9 +282,27 @@
$tooltip ||= '';
+ # Item7577: TWikiForms field types with configure attributes:
+ # Attributes are represented by key="value" parameters.
+ # Example attributes cell: | mandatory="1" style="color: blue;" |
+ # Legacy single character attribute flags M and H are supported as well.
+ # Example attributes cell: | M style="color: blue;" |
+ # results in:
+ # - $attributes: 'M'
+ # - $parameters: TWiki::Attrs object with:
+ # { mandatory => '1', style => 'color: blue;' }
$attributes ||= '';
- $attributes =~ s/\s*//go;
- $attributes = '' if( ! $attributes );
+ my $parameters = '';
+ if( $attributes =~ s/([a-zA-Z0-9]+\=.*)$// ) {
+ $parameters = $1;
+ }
+ $parameters .= ' hidden="1"' if( $attributes =~ /H/ );
+ $parameters .= ' mandatory="1"' if( $attributes =~ /M/ );
+ require TWiki::Attrs;
+ $parameters = new TWiki::Attrs( $parameters );
+ $attributes = '';
+ $attributes .= 'H' if( $parameters->{hidden} );
+ $attributes .= 'M' if( $parameters->{mandatory} );
my $definingTopic = "";
if( $title =~ /\[\[(.+)\]\[(.+)\]\]/ ) {
@@ -305,6 +326,7 @@
value => $vals,
tooltip => $tooltip,
attributes => $attributes,
+ parameters => $parameters,
definingTopic => $definingTopic,
web => $this->{web},
topic => $this->{topic}
@@ -612,8 +634,8 @@
foreach my $fieldDef ( @{$this->{fields}} ) {
my $fm = $meta->get( 'FIELD', $fieldDef->{name} );
next unless $fm;
- my $fa = $fm->{attributes} || '';
- unless ( $fa =~ /H/ ) {
+ my $fp = $fm->{parameters};
+ unless ( $fp && $fp->{hidden} ) {
$fieldFound = 1;
my $row = $rowTemplate;
# Legacy; was %A_TITLE% before it was $title
| Author: | TWiki:Main.PeterThoeny |
| Copyright: | © 2013-2014 Wave Systems Corp. © 2013-2015 TWiki:Main.PeterThoeny © 2013-2015 TWiki:TWiki.TWikiContributor |
| License: | GPL (GNU General Public License |
| Sponsor: | Wave Systems Corp. |
| Version: | 2015-05-29 |
| 2015-05-29: | TWikibug:Item7604 |
| 2014-12-10: | TWikibug:Item7556 |
| 2014-10-17: | TWikibug:Item7556 |
| 2014-10-13: | TWikibug:Item7556 |
| 2014-10-08: | TWikibug:Item7556selectstyle and containerstyle parameters |
| 2014-10-06: | TWikibug:Item7556 |
| 2014-10-04: | TWikibug:Item7556autocomplete+restrict type |
| 2014-10-04: | TWikibug:Item7556autocomplete+values row did not show up in TWikiForms topic |
| 2014-10-03: | TWikibug:Item7556 |
| 2014-10-02: | TWikibug:Item7556value: title syntax |
| 2014-10-01: | TWikibug:Item7556 |
| TWiki Dependency: | $TWiki::Plugins::VERSION 1.2 |
| CPAN Dependencies: | none |
| Other Dependencies: | none |
| Perl Version: | 5.005 |
| Plugin Benchmark |
GoodStyle nn%, FormattedSearch nn%, AutocompletePlugin nn% |
| Home: | http://TWiki.org/cgi-bin/view/Plugins/AutocompletePlugin |
| Feedback: | http://TWiki.org/cgi-bin/view/Plugins/AutocompletePluginDev |
| Appraisal: | http://TWiki.org/cgi-bin/view/Plugins/AutocompletePluginAppraisal |
| I | Attachment | History | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|---|
| |
AutocompletePlugin.md5 | r14 r13 r12 r11 r10 | manage | 0.2 K | 2015-05-29 - 20:50 | PeterThoeny | |
| |
AutocompletePlugin.tgz | r14 r13 r12 r11 r10 | manage | 12.8 K | 2015-05-29 - 20:50 | PeterThoeny | |
| |
AutocompletePlugin.zip | r14 r13 r12 r11 r10 | manage | 16.5 K | 2015-05-29 - 20:50 | PeterThoeny | |
| |
AutocompletePlugin_installer | r1 | manage | 3.7 K | 2015-05-29 - 20:50 | PeterThoeny |