diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 67d32e976..804d5a153 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -160,7 +160,7 @@ Widget.prototype.getVariableInfo = function(name,options) { }); // Parameters are an array of {name:, value:, multivalue:} pairs (name and multivalue are optional) $tw.utils.each(params,function(param) { - if(param.multiValue) { + if(param.multiValue && param.multiValue.length) { variables[param.name] = param.multiValue; } else { variables[param.name] = param.value || ""; @@ -233,8 +233,10 @@ Widget.prototype.resolveVariableParameters = function(formalParams,actualParams) paramMultiValue = typeof param === "string" ? [param] : (param.multiValue || [paramValue]); } // If we've still not got a value, use the default, if any - paramValue = paramValue || paramInfo["default"] || ""; - paramMultiValue = paramMultiValue || [paramValue]; + if(!paramValue) { + paramValue = paramInfo["default"] || ""; + paramMultiValue = [paramValue]; + } // Store the parameter name and value results.push({name: paramInfo.name, value: paramValue, multiValue: paramMultiValue}); } diff --git a/editions/test/tiddlers/tests/data/functions/FunctionDefaultValues.tid b/editions/test/tiddlers/tests/data/functions/FunctionDefaultValues.tid new file mode 100644 index 000000000..03c3a8a43 --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/FunctionDefaultValues.tid @@ -0,0 +1,16 @@ +title: Functions/FunctionDefaultValues +description: Use defaults for missing parameters in functions in filters +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .test(prefix:Default) [[ Content]addprefix] + +<$text text={{{ [.test[Special]] }}}/>,<$text text={{{ [.test[]] }}}/> + ++ +title: ExpectedResult + +

Special Content,Default Content

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8972.tid b/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8972.tid index 45203e0eb..bebbb5a6e 100644 --- a/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8972.tid +++ b/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8972.tid @@ -4,8 +4,8 @@ release: 5.4.0 tags: $:/tags/ChangeNote change-type: enhancement change-category: hackability -github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/8972 -github-contributors: Jermolene +github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/8972 https://github.com/TiddlyWiki/TiddlyWiki5/pull/9614 +github-contributors: Jermolene saqimtiaz This PR introduces a new filter run prefix `:let` that assigns the result of the filter run to a variable that is made available for the remaining filter runs of the filter expression. It solves the problem that previously it was impossible to compute values for filter operator parameters; parameters could only be a literal string, text reference or variable reference.