[pmwiki-devel] adding features to input tags: best practice?
Dominique Faure
dominique.faure at gmail.com
Tue Nov 14 14:24:11 CST 2006
On 11/14/06, Ben Stallings <Ben at interdependentweb.com> wrote:
> Hello again! One of the things I need to do in DataQuery is add some
> features to the (:input:) tags... notably, the mask=####-##-## parameter
> so that a JavaScript will help people type dates in the right format,
> because people can be really quirky about how they type dates otherwise,
> and SQL is not at all forgiving.
[...]
> If InputMarkup() were an object method, I could just extend the object.
> But it's a global function, so that's not an option. Should I
> redefine the input markup to call a different function? Or is there a
> better way that would be more compatible with other form recipes?
Few weeks ago, I did some experiments around it, but hadn't enough
time/needs to push them further. Anyway, here's my FormExtensions
recipe skeleton code that you may use as a starting point:
=====8<-----
# Reproduce the core loading order
if (IsEnabled($EnableAuthorTracking, 1))
include_once("$FarmD/scripts/author.php");
if (IsEnabled($EnablePrefs, 1))
include_once("$FarmD/scripts/prefs.php");
include_once("$FarmD/scripts/forms.php"); # must come after prefs
# Use our own markup processing
$MarkupTable['input']['rep'] =
"ExtendedInputMarkup(\$pagename, '$1', PSS('$2'))";
SDVA($ExtendedInputTags, array(
'mytag' => 'InputMyTag',
));
function ExtendedInputMarkup($pagename, $type, $args) {
global $InputTags, $ExtendedInputTags, $InputAttrs, $InputValues, $FmtV;
if (@$InputTags[$type]) return InputMarkup($pagename, $type, $args);
$f = $ExtendedInputTags[$type];
return isset($f)? $f($pagename, $type, $args) : "(:input $type $args:)";
}
# the (:input mytag ...:) handler itself
function InputMyTag($pagename, $type, $args) {
$opt = ParseArgs($args);
return '...';
}
=====8<-----
This code was about to provide handlers for new input types such as:
(:input mytag ...:)
and gracefully managing predefined ones.
Perhaps, should I make it a recipe by itself, you (and other form
extensions recipes) could bet on?
Regards,
Dom
More information about the pmwiki-devel
mailing list