The Formatting Rule field type enables a field to create content based on a stored Formatting Rule:
When the field is inserted, the named rule is populated and inserted between text markers without any tags (tags within tags are not allowed). When Repeat For Each Line is enabled, the rule will be populated once for each line in the field content and the content of the field changed to only contain that data for that line for the duration of the population.
Checking for Updates
In contrast to text links, where the content of the document is compared to the data, checking if an update is needed is handled differently. It would be too slow to re-render to entire content each time, so the links are tagged using the content of the original field and any named Fields. The field is only marked as needing an update if these change, or the Formatting Rule is updated.
A typical use would be a field containing a list of icons, where each icon should be displayed along with its name. For example:
On updates, any icons added or removed will be reflected in the document. This uses the Formatting Rule shown here:
The fields Picture Options point to the folder containing the images and the picture frame is tagged with the field. There’s also a text box with a field specifier, which is also populated.
In this example, the field contains a several names combined with an RGB value for the corresponding swatch:
The complexity is that Formatting Rule needs to break each line down into name and swatch. The swatch frame is given a Script Label so it can be identified – color. Post Processing on the Formatting Rule breaks out the color code part into an RGB swatch, finds the named frame and applies it:
c = SELECTION.root():getfield('Formatting Rule Field'):content();
name,code = string.match(c, "(.*)%((.*)%)");
icon = formattingrule:getframe("color");
The label should be just the name part, so we embed this logic into there:
name,code = string.match(field(“product name”), “(.*)%((.*)%)”);
Inserting that field now results in:
When Strip Whitespace is enabled in the alphanumeric field options, any trailing returns are truncated from the field.