{hero}

fields.setFormatter

Since: Editor 2.0

Define a function that can transform a value being set in a field.
Please note - this property requires the Editor extension for DataTables.

The full Editor reference documentation is available to registered users of Editor - the information shown below is a summary only. If you already have an Editor license please , alternatively an Editor license can be purchased on this site, or sign up for the free trial.

Description

Normally when working with Editor you simply want to present the end user with the raw, unmodified, data for them to edit it and send it back to the database. However, there are cases where it can be useful to modify the raw data before displaying it to the end user for editing - this option provides that ability.

Consider for example editing an ISO8601 date string - it isn't the friendliest format to show to your end users, so you might use this method to convert it to a more readable format (in combination with the datetime's format option to tell it what the format is). Then use fields.getFormatter to convert it back to ISO8601 to send to the server. This use case is shown in the example below.

Note that although fields.getFormatter and fields.setFormatter are typically used together, it is not required.