How can I cause numbers with no value to show up blank instead of NaN on forms?
Let’s say I have a User class with an optional weight (kgs) value, of type Number. If I edit a User in Flex I get the user object from the server and bind weightInput.text to user.weight. If weight is null on the server it will be translated to NaN in Flex, and then the value of weight in the edit form showes up as NaN. That is really inconvenient, as I would like it to just be blank if it has no value.
Is there a recommended/simple way to handle this? I would have thought that it is a really common problem.
One way is to use the
NumberFormatter:Or, if you don’t want to use a formatter, you can use
isNaN():Good lucks 🙂