Skip to content

Commit

Permalink
Item9056: small update for 1.6, refactoring and doc
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/FormPlugin@7559 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed May 26, 2010
1 parent 81976f7 commit e33f6c7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 48 deletions.
14 changes: 7 additions & 7 deletions data/Sandbox/FormPluginExamples.txt
Expand Up @@ -497,28 +497,28 @@ validate="nonempty"
hint="You cannot post anonymously"
}%
%FORMELEMENT{
name="Your salary"
name="Estimated team earnings"
type="text"
title="Your salary:"
title="Estimated team earnings:"
default=""
mandatory="on"
validate="float"
hint="You may include decimal numbers"
hint="You may use a decimal number"
}%
%FORMELEMENT{
name="Checkname"
name="Team members"
type="checkbox"
title="Who earns more than you:"
title="Team members:"
options="mary=Mary M, peter=Peter P, annabel=Annabel A, nicky=Nicky N, jennifer=Jennifer J"
fieldformat="$e<br />"
mandatory="on"
validate="nonempty"
hint="Just point the finger"
hint="Select at least one person"
}%
%FORMELEMENT{
name="action"
type="submit"
default="Try me"
default="Send"
}%
%ENDFORM%

Expand Down
6 changes: 3 additions & 3 deletions data/System/FormPlugin.txt
Expand Up @@ -10,15 +10,15 @@
* Add input fields, textareas, dropdown select boxes, checkboxes, radio buttons
* Set preselected values
* Create a uniform layout
* Call Foswiki scripts (view, edit, upload, save) or custom scripts
* Call Foswiki scripts (view, edit, upload, save, etcetera) or custom scripts
* Use entered field values as variables
* Validate the form before it performs its action
* Usability tested error feedback
* Add Javascript functions for advanced interaction

Example of validation error feedback:

<div class="foswikiImage"><img src="%ATTACHURLPATH%/screenshot_validation_example.png" alt="Example of validation error feedback" width='738' height='535' /></div>
<div class="foswikiImage"><img src="%ATTACHURLPATH%/screenshot_validation_example.png" alt="Example of validation error feedback" width='709' height='483' /></div>


---++ Introduction
Expand Down Expand Up @@ -557,7 +557,7 @@ Plugin settings are stored as preferences variables. To reference a plugin setti
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 24 May 2010 | 1.6 Arthur Clemens: %BR%\
| 26 May 2010 | 1.6 Arthur Clemens: %BR%\
Bug fixes: \
%BB% Fixed pre-selecting multiple items in multi-select form elements. \
%BB% All Foswiki scripts are now allowed in =action=. \
Expand Down
52 changes: 15 additions & 37 deletions lib/Foswiki/Plugins/FormPlugin.pm
Expand Up @@ -39,7 +39,6 @@ my $currentTopic;
my $currentWeb;
my $debug;
my $currentForm;
my $elementcssclass;
my $doneHeader;
my $defaultTitleFormat;
my $defaultElementFormat;
Expand Down Expand Up @@ -148,7 +147,6 @@ sub _initTopicVariables {
$debug = $Foswiki::cfg{Plugins}{FormPlugin}{Debug};

$currentForm = {};
$elementcssclass = '';
$doneHeader = 0;
$defaultTitleFormat =
Foswiki::Func::expandTemplate('formplugin:format:element:title');
Expand Down Expand Up @@ -194,15 +192,14 @@ Called at _startForm

sub _initFormVariables {

$elementcssclass = '';

# form attributes we want to retrieve while parsing FORMELEMENT tags:
undef $currentForm;
$currentForm = {
'name' => 'untitled',
'elementformat' => $defaultElementFormat,
'elementcssclass' => '',
'noFormHtml' => '',
'showErrors' => 'above'
'showErrors' => 'above',
};
}

Expand Down Expand Up @@ -456,7 +453,7 @@ sub _renderHtmlStartForm {
my $id = $params->{'id'} || $name;

my $method = _method( $params->{'method'} || '' );
$elementcssclass = $params->{'elementcssclass'} || '';
$currentForm->{'elementcssclass'} = $params->{'elementcssclass'} || '';
my $formcssclass = $params->{'formcssclass'} || '';
my $webParam = $params->{'web'} || $web || $currentWeb;
my $topicParam = $params->{'topic'} || $topic || $currentTopic;
Expand Down Expand Up @@ -1057,12 +1054,8 @@ sub _formElement {

_addHeader();

my $element = _getFormElementHtml(@_);

$element =
'<noautolink>'
. $element
. '</noautolink>'; # prevent wiki words inside form fields
my $element = '<noautolink>' . _getFormElementHtml(@_) . '</noautolink>'; # prevent wiki words inside form fields

my $type = $params->{'type'};
my $name = $params->{'name'};

Expand All @@ -1075,33 +1068,18 @@ sub _formElement {
my $javascriptCalls = '';
my $focus = $params->{'focus'};
if ($focus) {
my $focusCall =
'<script type="text/javascript">foswiki.Form.setFocus("'
. ( $currentForm->{'name'} || '' ) . '", "'
. $name
. '");</script>';
my $focusCall = Foswiki::Func::expandTemplate('formplugin:javascript:focus:inline');
$focusCall =~ s/\$formName/$currentForm->{'name'}/;
$focusCall =~ s/\$fieldName/$name/;
$javascriptCalls .= $focusCall;
}
my $beforeclick = $params->{'beforeclick'};
if ($beforeclick) {
my $formName = $currentForm->{'name'};
my $beforeclickCall = '';
$beforeclickCall .= '<script type="text/javascript">';
if ( $formName eq '' ) {
$beforeclickCall .=
'var field=document.getElementsByName("'
. $name
. '")[0]; var formName=field.form.name;';
}
else {
$beforeclickCall .= 'var formName="' . $formName . '";';
}
$beforeclickCall .=
'var el=foswiki.Form.getFormElement(formName, "'
. $name
. '"); foswiki.Form.initBeforeFocusText(el,"'
. $beforeclick . '");';
$beforeclickCall .= '</script>';
my $beforeclickCall = Foswiki::Func::expandTemplate('formplugin:javascript:beforeclick:inline');
$beforeclickCall =~ s/\$formName/$currentForm->{'name'}/;
$beforeclickCall =~ s/\$fieldName/$name/;
$beforeclickCall =~ s/\$beforeclick/$beforeclick/;
$javascriptCalls .= $beforeclickCall;
}

Expand Down Expand Up @@ -1178,11 +1156,11 @@ sub _formElement {

$format = _renderFormattingTokens($format);

if ($elementcssclass) {
if ($currentForm->{'elementcssclass'}) {

# not for hidden classes, but these are returned earlier in sub
my $classAttr = ' class="' . $elementcssclass . '"';
$format = CGI::div( { class => $elementcssclass }, $format );
my $classAttr = ' class="' . $currentForm->{'elementcssclass'} . '"';
$format = CGI::div( { class => $currentForm->{'elementcssclass'} }, $format );
}

# error?
Expand Down
Binary file modified pub/System/FormPlugin/screenshot_validation_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion templates/formplugin.tmpl
Expand Up @@ -33,4 +33,8 @@
%TMPL:DEF{formplugin:message:author:missing_element_name}%%TMPL:P{formplugin:message:start}%parameter =name= is required for =FORMELEMENT= (missing at element with type: =$type=).%TMPL:END%

%TMPL:DEF{formplugin:message:no_redirect:title}%Could not redirect%TMPL:END%
%TMPL:DEF{formplugin:message:no_redirect:body}% Check if =AllowRedirectUrl= has been set in [[%SCRIPTURL{configure}%#Environment$SecurityAndAuthentication][configure]] and if the url [[$url]] is listed in configure's [[%SCRIPTURL{configure}%#GeneralPathSettings][General path settings]].%TMPL:END%
%TMPL:DEF{formplugin:message:no_redirect:body}% Check if =AllowRedirectUrl= has been set in [[%SCRIPTURL{configure}%#Environment$SecurityAndAuthentication][configure]] and if the url [[$url]] is listed in configure's [[%SCRIPTURL{configure}%#GeneralPathSettings][General path settings]].%TMPL:END%

%TMPL:DEF{formplugin:javascript:focus:inline}%<script type="text/javascript">foswiki.Form.setFocus("$formName", "$fieldName");</script>%TMPL:END%

%TMPL:DEF{formplugin:javascript:beforeclick:inline}%<script type="text/javascript">var formName="$formName";var el=foswiki.Form.getFormElement(formName, "$fieldName"); foswiki.Form.initBeforeFocusText(el,"$beforeclick");</script>%TMPL:END%

0 comments on commit e33f6c7

Please sign in to comment.