Formatter - smbc-digital/form-builder GitHub Wiki

Provides Formatting to Tag Parsers

Current Formatters

Formatter Output
full-date Thursday 1 December 2020
time-only 7am or 12:30pm

Example

Displayed the question dateValue with the full-date formatter

{
    "Type": "p",
    "Properties": {
        "Text": "The selected date is {{QUESTION:dateValue:full-date}}"
    }
},

"full-date"

This is the same as writing dateTimeObject.ToString("dddd d MMMM yyyy")

eg. {{QUESTION:variable-key:full-date}} Output => "Thursday 1 December 2020"

"time-only"

This is the same as writing dateTimeObject.ToString("h:mmtt") or dateTimeObject.ToString("htt"), depending on if there are minutes to display or not. This will display in lowercase.

eg. {{QUESTION:variable-key:time-only}} Outout => "7am", "12pm", "12:30pm", "5:45pm"

Adding Formatters for TagParser

in form-builder/src/TagParsers/Formatters/ add a class

    public class YourFormatter : IFormatter
    {
        public string FormatterName { get => "your-string-identifier"; }

        public string Parse(string value)
        {
            return value.WithSomeFormatting()
        }
    }