Tags:
create new tag
view all tags

SID-02240: Question about Form Attributes

Status: Answered Answered TWiki version: 6.0.1 Perl version:
Category: CategoryForms Server OS: Last update: 7 years ago

I find EDITFORMFIELD really handy to use but am wondering if there was any way to include the HTML placeholder attribute? I've read the documentation on forms and EDITFORMFIELD however am not fully understanding the "attributes" comments and haven't had any luck finding an example.

For example:

<input type="text" name="TestField" size="30" class="twikiInputField twikiEditFormTextField" placeholder="This is placeholder text"> 

My guess at TWiki markup up (not working):

%EDITFORMFIELD{"TestField" topic="TestTopic" placeholder="This is placeholder text"}%

-- Jani Hamalainen - 2016-08-11

Discussion and Answer

Reading the code, the EDITFORMFIELD should pick up any foo="bar" parameter. Test:

Server OS:

Written as:

%EDITFORMFIELD{ "form" type="start" }%
Server OS:
%EDITFORMFIELD{ "ServerOS" type="text" form="SupportForm" placeholder="This is placeholder text" }%
%EDITFORMFIELD{ "form" type="end" }%

The key is to specify a type="text" parameter.

-- Peter Thoeny - 2016-08-12

Thanks Peter. Is there a good place where I could add some examples to the documentation (I noticed you updated TWikiForms to include placeholder which I think is a really handy attribute)?

Also, is there something I'm missing trying to use placeholder in a textarea?

Example textarea:

I've tried:

%EDITFORMFIELD{ "form" type="start" }%

Text Area Field with Size:  %EDITFORMFIELD{ "TestFieldArea" type="textarea" form="Sandbox.TestPlaceholderForm" size="100x5" placeholder="This is placeholder text" }%
Text Area Field with Rows and Cols:  %EDITFORMFIELD{ "TestFieldArea" type="textarea" form="Sandbox.TestPlaceholderForm" rows="5" cols="100" placeholder="This is placeholder text" }%

%EDITFORMFIELD{ "form" type="end" }%

Output:

Verify Placeholder works in text field:

Text Area Field with Size:

Text Area Field with Rows and Cols:


-- Jani Hamalainen - 2016-08-12

The type="" is designed for HTML input tags. A textarea is related, but not an input tag, hence not part of the current spec. Nevertheless since this is useful we can enhance EDITFORMFIELD to support type="textarea"; proposal at VarEDITFORMFIELDwithTextarea.

Patch:

--- TWiki/Render.pm   (revision 30200)
+++ TWiki/Render.pm   (working copy)
@@ -1525,6 +1525,28 @@
         my $html = '</form>';
         return $html;
 
+    } elsif( $type =~ /^textarea$/ ) {
+        # special case, construct <textara></textarea> tags
+        my $html = "<textarea name=\"$formField\"";
+        my $needsClass = 1;
+        my $class = 'twikiTextarea';
+        foreach my $key ( keys %$params ) {
+            next if( $key =~ /^(_DEFAULT|_RAW|name|size|type|text|value)$/i );
+            $needsClass = 0 if( $key =~ /^class$/i );
+            $html .= " $key=\"" . $params->{$key} . '"';
+        }
+        my $size = $params->{size} || '';
+        if( $size =~ /^([0-9]+)x([0-9]+)$/ ) {
+            $html .= " cols=\"$1\" rows=\"$2\"";
+        } elsif( $size =~ /^([0-9]+)$/ ) {
+            $html .= " cols=\"$1\" rows=\"6\"";
+        }
+        if( $needsClass ) {
+            $html .= ' class="twikiTextarea"';
+        }
+        $html .= '>' . $value . '</textarea>';
+        return $html;
+
     } elsif( $type ) {
         # special case, construct an <input type="" /> tag
         my $html = "<input name=\"$formField\" type=\"$type\"";

-- Peter Thoeny - 2016-08-14

Thanks a lot Peter. I've added the patch to my installation and it's working great smile

-- Jani Hamalainen - 2016-08-19

      Change status to:
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.
SupportForm
Status Answered
Title Question about Form Attributes
SupportCategory CategoryForms
TWiki version 6.0.1
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2016-08-19 - JaniHamalainen
 
  • 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-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.