Message Boards Message Boards

0
|
3379 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

modify Association created by FormFunction

Posted 10 years ago

Hi,

I want to create a FormFunction dynamically which means the number and the names of variables asked for in the FormFunction can change. Therefore I would need to have direct access to the Association created by the FormFunction, for example to Apply it's values to an StringTemplate. So far I was not able to figure out how to access this.

Any help is highly appreciated.

Ulrich

POSTED BY: Ulrich Arndt
3 Replies
Posted 10 years ago

Sorry, I pasted it into the code section but it looks like many things have not been present corrently. I attach now an notebook with the example code.

Ulrich

Attachments:
POSTED BY: Ulrich Arndt

I am interested to see what you came up with: could you format your code using the formatting tools? Thanks, David

POSTED BY: David Reiss
Posted 10 years ago

At least I came up with something with will do the trick - whereas I was hoping for something more elegant... I generate the form function fields and the association as strings. Then I StringReplace these in a FormFunction string and call ToExpression and Evaluate on this. It is working but would be interested in better solutions...

tmpl1 = "Today is Weekday and tomorrow it will Weather"; tmpl2 = "My hous is build with a HousePart1 and a HousePart2 and \ will have GardenPart in the garden"; tmplbase = tmpl2; placeHolder = Union[StringCases[tmplbase, Shortest["" ~~ x__ ~~ ""] -> x]]; fffields = {"\"a" <> ToString[#] <> "\"", "\"" <> placeHolder[[#]] <> "\""} -> "String" & /@ Range@Length@placeHolder; astxt = "\"" <> placeHolder[[#]] <> "\" -> #a" <> ToString[#] & /@ Range@Length@placeHolder; txt = " FormFunction[<<<fieldlist>>>, Module[{tmpl,as},

tmpl=StringTemplate[tmplbase];[IndentingNewLine] \ as=Association[<<<aslist>>>];[IndentingNewLine] \ ExportForm[Print[TemplateApply[tmpl,as]],\"String\"]; ]& ] "; txt = StringReplace[ txt, {"<<<fieldlist>>>" -> ToString[fffields], "<<<aslist>>>" -> ToString[astxt]}]; Evaluate[ToExpression[txt]][];

POSTED BY: Ulrich Arndt
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract