Skip to content

Commit

Permalink
Encoding for form helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
perdjurner committed May 14, 2017
1 parent 4a5825c commit 9676374
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
8 changes: 4 additions & 4 deletions wheels/events/onapplicationstart.cfm
Expand Up @@ -281,7 +281,7 @@ public void function onApplicationStart() {
application.$wheels.functions.average = {distinct=false, parameterize=true, ifNull=""};
application.$wheels.functions.belongsTo = {joinType="inner"};
application.$wheels.functions.buttonTo = {onlyPath=true, host="", protocol="", port=0, text="", image=""};
application.$wheels.functions.buttonTag = {type="submit", value="save", content="Save changes", image="", prepend="", append=""};
application.$wheels.functions.buttonTag = {type="submit", value="save", content="Save changes", image="", prepend="", append="", encode=false};
application.$wheels.functions.caches = {time=60, static=false};
application.$wheels.functions.checkBox = {label="useDefaultLabel", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", errorElement="span", errorClass="fieldWithErrors", checkedValue=1, unCheckedValue=0};
application.$wheels.functions.checkBoxTag = {label="", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", value=1};
Expand Down Expand Up @@ -345,12 +345,12 @@ public void function onApplicationStart() {
application.$wheels.functions.simpleFormat = {wrap=true};
application.$wheels.functions.startFormTag = {onlyPath=true, host="", protocol="", port=0, method="post", multipart=false, prepend="", append=""};
application.$wheels.functions.styleSheetLinkTag = {type="text/css", media="all", head=false, encode=false};
application.$wheels.functions.submitTag = {value="Save changes", image="", prepend="", append=""};
application.$wheels.functions.submitTag = {value="Save changes", image="", prepend="", append="", encode=false};
application.$wheels.functions.sum = {distinct=false, parameterize=true, ifNull=""};
application.$wheels.functions.textArea = {label="useDefaultLabel", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", errorElement="span", errorClass="fieldWithErrors"};
application.$wheels.functions.textAreaTag = {label="", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel=""};
application.$wheels.functions.textField = {label="useDefaultLabel", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", errorElement="span", errorClass="fieldWithErrors"};
application.$wheels.functions.textFieldTag = {label="", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel=""};
application.$wheels.functions.textField = {label="useDefaultLabel", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", errorElement="span", errorClass="fieldWithErrors", encode=false};
application.$wheels.functions.textFieldTag = {label="", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", encode=false};
application.$wheels.functions.timeAgoInWords = {includeSeconds=false};
application.$wheels.functions.timeSelect = {label=false, labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", errorElement="span", errorClass="fieldWithErrors", includeBlank=false, order="hour,minute,second", separator=":", minuteStep=1, secondStep=1, twelveHour=false};
application.$wheels.functions.timeSelectTags = {label="", labelPlacement="around", prepend="", append="", prependToLabel="", appendToLabel="", includeBlank=false, order="hour,minute,second", separator=":", minuteStep=1, secondStep=1, twelveHour=false};
Expand Down
27 changes: 17 additions & 10 deletions wheels/view/forms.cfm
Expand Up @@ -138,12 +138,14 @@ public string function startFormTag(
* @image File name of the image file to use in the button form control.
* @prepend [see:textField]
* @append [see:textField]
* @encode [see:styleSheetLinkTag].
*/
public string function submitTag(
string value,
string image,
string prepend,
string append
string append,
boolean encode
) {
$args(name="submitTag", reserved="type,src", args=arguments);
local.rv = arguments.prepend;
Expand All @@ -160,7 +162,7 @@ public string function submitTag(
local.rv = Replace(local.rv, "<img", "<input");
} else {
arguments.type = "submit";
local.rv &= $tag(name="input", skip="image,append,prepend", attributes=arguments, encode=false);
local.rv &= $tag(name="input", skip="image,append,prepend,encode", attributes=arguments, encode=arguments.encode);
}
local.rv &= local.append;
return local.rv;
Expand All @@ -178,14 +180,16 @@ public string function submitTag(
* @image File name of the image file to use in the button form control.
* @prepend [see:textField]
* @append [see:textField]
* @encode [see:styleSheetLinkTag].
*/
public string function buttonTag(
string content,
string type,
string value,
string image,
string prepend,
string append
string append,
boolean encode
) {
$args(name="buttonTag", args=arguments);
Expand All @@ -195,19 +199,22 @@ public string function buttonTag(
local.args.type = "image";
local.args.source = arguments.image;
arguments.content = imageTag(argumentCollection=local.args);
arguments.encode = arguments.encode ? "attributes" : false;
}
// save necessary info from arguments and delete afterwards
local.content = arguments.content;
local.prepend = arguments.prepend;
local.append = arguments.append;
local.encode = arguments.encode;
StructDelete(arguments, "content");
StructDelete(arguments, "image");
StructDelete(arguments, "prepend");
StructDelete(arguments, "append");
StructDelete(arguments, "encode");
// create the button
return local.prepend & $element(name="button", content=local.content, attributes=arguments, encode=false) & local.append;
return local.prepend & $element(name="button", content=local.content, attributes=arguments, encode=local.encode) & local.append;
}
/**
Expand Down Expand Up @@ -274,7 +281,8 @@ public string function $createLabel(
required any objectName,
required string property,
required string label,
required string prependToLabel
required string prependToLabel,
boolean encode=false
) {
local.rv = arguments.prependToLabel;
local.attributes = {};
Expand All @@ -286,9 +294,7 @@ public string function $createLabel(
if (StructKeyExists(arguments, "id")) {
local.attributes.for = arguments.id;
}
local.rv &= $tag(name="label", attributes=local.attributes, encode=false);
local.rv &= arguments.label;
local.rv &= "</label>";
local.rv &= $element(name="label", content=arguments.label, attributes=local.attributes, encode=arguments.encode);
return local.rv;
}
Expand All @@ -305,13 +311,14 @@ public string function $formBeforeElement(
required string prependToLabel,
required string appendToLabel,
required string errorElement,
required string errorClass
required string errorClass,
boolean encode=false
) {
local.rv = "";
arguments.label = $getFieldLabel(argumentCollection=arguments);
if ($formHasError(argumentCollection=arguments) && Len(arguments.errorElement)) {
// the input has an error and should be wrapped in a tag so we need to start that wrapper tag
local.rv &= $tag(name=arguments.errorElement, class=arguments.errorClass, encode=false);
local.rv &= $tag(name=arguments.errorElement, class=arguments.errorClass, encode=arguments.encode);
}
if (Len(arguments.label) && arguments.labelPlacement != "after") {
local.rv &= $createLabel(argumentCollection=arguments);
Expand Down
6 changes: 4 additions & 2 deletions wheels/view/formsobject.cfm
Expand Up @@ -21,6 +21,7 @@
* @errorClass The class name of the HTML tag that wraps the form control when there are errors.
* @type Input type attribute. Common examples in HTML5 and later are text (default), email, tel, and url.
* @labelClass String added to the label's class.
* @encode [see:styleSheetLinkTag].
*/
public string function textField(
required any objectName,
Expand All @@ -35,7 +36,8 @@ public string function textField(
string appendToLabel,
string errorElement,
string errorClass,
string type="text"
string type="text",
boolean encode
) {
$args(name="textField", reserved="name", args=arguments);
arguments.objectName = $objectName(argumentCollection=arguments);
Expand All @@ -52,7 +54,7 @@ public string function textField(
if (!StructKeyExists(arguments, "value") || !Len(arguments.value)) {
arguments.value = $formValue(argumentCollection=arguments);
}
return local.before & $tag(name="input", skip="objectName,property,label,labelPlacement,prepend,append,prependToLabel,appendToLabel,errorElement,errorClass,association,position", skipStartingWith="label", attributes=arguments, encode=false) & local.after;
return local.before & $tag(name="input", skip="objectName,property,label,labelPlacement,prepend,append,prependToLabel,appendToLabel,errorElement,errorClass,association,position,encode", skipStartingWith="label", attributes=arguments, encode=arguments.encode) & local.after;
}
/**
Expand Down
4 changes: 3 additions & 1 deletion wheels/view/formsplain.cfm
Expand Up @@ -16,6 +16,7 @@
* @prependToLabel [see:textField].
* @appendToLabel [see:textField].
* @type [see:textField].
* @encode [see:styleSheetLinkTag].
*/
public string function textFieldTag(
required string name,
Expand All @@ -26,7 +27,8 @@ public string function textFieldTag(
string append,
string prependToLabel,
string appendToLabel,
string type="text"
string type="text",
boolean encode
) {
$args(name="textFieldTag", args=arguments);
arguments.property = arguments.name;
Expand Down

0 comments on commit 9676374

Please sign in to comment.