Recent Changes - Search:

PmWiki

pmwiki.org

00792

Summary: Add ability to pre-fill "textarea" input control with a value
Created: 2006-08-24 13:44
Status: Discussion
Category: Feature
From: Pm
Assigned:
Priority: 55444 433
Version: 2.1.14
OS:

Description: Currently the (:input textarea:) markup doesn't have a convenient way of pre-filling the contents of the textarea. We should find a good way to do this.

The primary stumbling block at the moment is having a good markup for it. Suggestions welcomed below. Votes welcomed above.

Pm


In UpdateForm I implemented this with the same value= markup that the other form tags use, for example (:update type=textarea name=fieldname value="default text":) or just (:update textarea fieldname "default text":) Users need not know that the <textarea> HTML tag has no value parameter; all that matters is that the (:input:) tag has one!

Ben Stallings August 24, 2006, at 05:02 PM

The downside of this is that it doesn't allow multi-line content for the pre-filled textarea, and since half the point of having a textarea is that it uses multi-line input, I don't think it quite fits the bill.
Kathryn Andersen August 24, 2006, at 05:43 PM
Does it not allow multiple lines using \\? (Simple tables do - so it's worth trying, if you haven't.) - TeganDowling

From the mailing list: [1] [2]

It should be at least possible to pre-fill the textarea from a script/recipe with the $InputValues array. --Petko January 25, 2007, at 04:13 AM

Currently the markup (:input textarea value="Some text":) outputs <textarea value="Some text"></textarea>. This is not correct, why is it so difficult to output <textarea>Some text</textarea>? This tag has more or less the same problems as the (:markup:) command. We could use

 (:input textarea value="[=
The text here...
=]":)
or even
(:input textarea:)[=
The text here...
=]

just like in (:markup:), or something similar. Or have a closing (:input textareaend:) command: this string is really unusual, so I don't believe there will be many problems in practice (i.e. the textarea contains the same string).

The problem is also similar to the great new Page text variables, what if a (:variable:) contains ":)"? It will not, or it will be ignored, or it will break, we accept to take this risk. --Petko January 25, 2007, at 04:25 AM


Ok, here is what I am using currently:

Markup('textarea', '>{$var}',//, '>input'
  '/\\(:textarea\\s*(.*?):\\)(.*?)\\(:textareaend:\\)/esi',
  "FmtTextArea(\$pagename,PSS('$1'),PSS('$2'))");
function FmtTextArea($pagename, $args, $value)
{
	global $InputValues;
	$opt = ParseArgs($args);
	$attributes = array('name', 'id', 'class', 'rows', 'cols', 'maxlength', 'accesskey', 'disabled', 'readonly', 'style');
	$myattr = "";
	foreach($attributes as $k){if(isset($opt[$k])) $myattr.=" $k=\"".htmlspecialchars($opt[$k])."\"";}
	if(!strlen($value))$value = htmlspecialchars(@$InputValues[@$opt['name']]);
	return Keep(FmtPageName("<textarea $myattr>$value</textarea>", $pagename));
}
You can write
(:textarea name=area1 cols=40 rows=4 class=inputbox:)Some text
New line.(:textareaend:)

It is more importanly possible to pre-populate the content from a script/recipe with the $InputValues array (I am using it this way). Hope this helps somebody. --Petko February 24, 2007, at 06:43 AM

(Now added to Cookbook.Textarea. --Petko)

Edit - History - Print - Recent Changes - Search
Page last modified on September 03, 2008, at 06:36 AM