This question about Topic Markup Language and applications: Answered

Default values in Data Forms: macro expansion only once

I would like to have default values in a data form constructed by macro expansion. That's of course no problem, but how do I achieve that the macro expands only once i.e. the moment I add the form to the topic?

My application for this is, that when I search the topics I get the macro expanded in the context of the topic where my search lives, which renders the wrong text. Instead I would like to have to have the text rendered as if the macro were expanded within the context of the found topic. %BASETOPIC% doesn't help, so it would be nice, to have the macro expanded only once and save only the expanded value into the form field.


Well, there are some options for this. If you truly want to save some text after its macros have been expanded,FrequentlyAskedQuestions as the value of a formfield, some things you could try...
  • Can you set up the desired formfield value as a part of the topic creation process? Or are your users using the "add/change form" button in the editor?
  • Do you just want this to happen at topic creation? Or is it okay to re-evaluate the expression from the DataForm on every save?
  • Do you really need this feature? Have you tried %TOPIC% instead of %BASETOPIC%?
    • Are you having trouble querying formfields, or is the display of them?
    • Can you provide a bit more information about your application or the problem you are trying to solve?

-- PaulHarvey - 05 Jul 2011

  • As this is my first try using data forms I do not really know how to set up the formfield value as a part of the topic creation process, so the option was to use the add/change form button.
  • It would be perfectly ok to re-evaluate on save.
  • Of course I have tried %TOPIC% which does not work either.

My application is a kind of support database for a customer. I have a MachineForm describing the technical data of a server machine in the customer's web cluster. One of the formfields is the FQDN of the machine. The topics each one describing one server and having attached the MachineForm are named the same as the machine itself. Now it's easy to get a default value for the FQDN formfield by using $percntCALC{$dollarLOWER($percntTOPIC$percnt)}$percnt.examplecustomer.com as value in the form definition. Now there is another topic named MachineList containing a search which ouputs this formfield. Now %TOPIC% is expanded in the context of MachineList resulting in "machinelist.examplecustomer.com" instead of the wanted "machinename.examplecustomer.com". That's why I'm looking for a possibility to construct a default value for a formfield using macro expansion but saving only the expanded value. Hope this clears things up smile

-- ValentinMayer - 05 Jul 2011

Well, there are some possibilities.
  • Use a custom topic-creator (like the one you can find at FrequentlyAskedQuestions), which saves the desired value on creation.
  • Use TemplateTopics (special VarSTARTSECTION attributes) to expand a macro on initial creation, but I'm not sure if it can be done inside %META:FIELD.
  • I'm quietly working some new formfield types, one of which is dynamic+onsave, but that's a long way from releasable.

But the easiest of all, is just to modify your SEARCH format so that it lower-case's the formfield value on each hit, something like:
%SEARCH{
  "form.name='QuestionForm'"
  type="query"
  web="%WEB%"
  pager="on"
  pagesize="10"
  nonoise="on"
  format="   * [[$web.$topic]] - $formfield(Status) vs $percntQUERY{lc('$web.$topic'/Status)}$percnt"
}%

Test:
Page 1 of 215 Next >

-- PaulHarvey - 06 Jul 2011

QuestionForm edit

Subject Topic Markup Language and applications
Extension
Version Foswiki 1.1.3
Status Answered
Topic revision: r4 - 06 Jul 2011, PaulHarvey
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy