Is their any way to format form fields, like we have formatCell in listgrid?
Announcement
Collapse
No announcement yet.
X
-
Hi Spayaga
We don't currently have a documented way to do this.
Supported approaches include providing the form with values that are already formatted, or using a valueMap on the field in question.
Alternatively, if you need true dynamic formatting of values, we do actually have a method that should achieve this:
FormItem.mapValueToDisplay(dataValue)
This method takes a data value, and returns the value to display.
The default implementation handles applying valueMaps to the data value, as well as various other standard mappings (for example mapping null or undefined to an empty string for text items).
If you're planning to apply a conversion to a freely editable field such as a textItem you'll also need a corollary method to parse the data value out of a modified display value. This can be achieved by overriding FormItem.mapDisplaytoValue(displayValue) which takes the display value (as currently visible to the user) and returns a data value to store.
Note: this method is not publicly documented. We may be providing a documented, public API to do this kind of formatting/parsing of values in a future release, at which point we'll be sure to update this thread.Last edited by Isomorphic; 27 Feb 2008, 16:18.
-
For the benefit of people who discover this thread while searching the forums:
As of version 10.1 (SmartGWT 5.1), the mapValueToDisplay() and mapDisplayToValue() methods have been made public. However, they are intended as callable APIs only, not as override points, so the suggestions we make in this very old thread are invalid. See the mapValueToDisplay() and mapDisplayToValue() documentation for supported alternative methods of formatting and parsing FormItem values (such as the formatEditorValue() and parseEditorValue() pair)
Comment
Comment