Custom Converter - Numbers or Text
Feb 11, 2014
What I need to do is let the user put in either strings or numbers. If a string, leave it alone. If it's a number, I want it to be formatted with thousands separators. Turns out to be pretty easy, now that I have a basis for it (my last post of a few minutes ago). I need this because the entry is for the number of miles of coverage, if "Unlimited", than it's that, otherwise it's whatever the miles entered are. I could have created an "unlimited" button, but in this case I thought letting the user enter whatever would be better. In my sample here, I am appending a bit of text just to show it worked.

                <xp:customConverter getAsObject="#{
var dIn:float=parseFloat(value);
//this is a text string
return value +  " converted";
} else {
 return dIn.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// based on:
} catch(e){
        print (e);

Sometimes, getting a handle on something really helps out. I know I'm on the simple end of what custom converters can do, but they are so much clearer in my brain now.
It's in my snippet above, but I based this on this post on StackOverflow.
This is an archive of my previous blog attachments are in the download control