Creating form functions
Moving on
In the steps shown above we created a single function – if you create aditional classes like DemoFunctionFactory and DemoFunction and register them with an aditional <add /> element in Composite.configuration you can build a small library of Form Functions.
Form Functions are also great for providing options for items like select boxes. If your function returns a structure like Dictionary<Guid, string> you can use it in a setup like this:
<KeySelector Label="Category" Help="Category" OptionsKeyField="Key" OptionsLabelField="Value" xmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0"> <KeySelector.Selected> <cms:bind source="Id" /> </KeySelector.Selected> <KeySelector.Options> <CategoryOptions xmlns="http://www.mycompany.net/ns/c1/formfunctions"> <CategoryOptions.PageId> <cms:read source="PageIdForeignKey" /> </CategoryOptions.PageId> </CategoryOptions> </KeySelector.Options> </KeySelector>
This markup invokes the default selector which gets its options from a function registered as "CategoryOptions" living in the namespace http://www.mycompany.net/ns/c1/formfunctions. The function is passed data from the forms bindings collection.