|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Just a tidbit for those who might not have use iif before
I have never really used iif before, I was aware it existed but didn'tPeterson, Chris 03/22/07 04:11 P Uh oh. You're probably about to get hammered with responses related to theRob Wilkerson 03/22/07 04:16 P ...and about whether Cost is truly a Boolean...John Rossi 03/22/07 04:21 P Here come the Iif police.Andy Matthews 03/22/07 04:18 P Quick, someone find a way to make that need an evaluate().Heald, Timothy J 03/22/07 04:22 P I think I heard something about them going back on tour this year...Rob Wilkerson 03/22/07 06:35 P > dollarformat(iif(Cost, cost, 0))Justin Scott 03/22/07 04:25 P I'm assuming there is a noticeable difference in using IFF? Recently I've been using it quite heavily in forms now i.e.Richard Cooper 03/23/07 03:41 A checked="#something eq 'somethingelse#"Rob Wilkerson 03/23/07 07:34 A First better way: Don't use strings for booleans!Peter Boughton 03/23/07 09:10 A I have never really used iif before, I was aware it existed but didn't really see a good place for it. Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break) This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris Uh oh. You're probably about to get hammered with responses related to the performance cost... ----- Excess quoted text cut - see Original Post for more ----- ...and about whether Cost is truly a Boolean... Uh oh. You're probably about to get hammered with responses related to the performance cost... ----- Excess quoted text cut - see Original Post for more ----- Here come the Iif police. I have never really used iif before, I was aware it existed but didn't really see a good place for it. Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break) This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris Quick, someone find a way to make that need an evaluate(). Here come the Iif police. I have never really used iif before, I was aware it existed but didn't really see a good place for it. Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break) This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris I think I heard something about them going back on tour this year... ----- Excess quoted text cut - see Original Post for more ----- > dollarformat(iif(Cost, cost, 0)) You could also use the val() function around the cost variable to do the same thing more efficiently. It will also correct for unexpected non-integer characters in the variable as well. I've found that in almost any situation where iif() looks like it's needed, there's a better way. There are exceptions, but I don't think this is one of them. -Justin Scott I'm assuming there is a noticeable difference in using IFF? Recently I've been using it quite heavily in forms now i.e. <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#IIF(something eq 'somethingelse', DE('Yes'), DE('No'))#" /> Are there better ways of doing this? checked="#something eq 'somethingelse#" That should work just fine. No need for the iff() in this case. ----- Excess quoted text cut - see Original Post for more ----- First better way: Don't use strings for booleans! <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#IIF(something eq 'somethingelse', 1, 0)#" /> Second better way: Don't write "if True then True else False"! <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#(something eq 'somethingelse')#" /> (parenthesis are unnecessary here, but I feel they make it more readable) Third better way: Don't use cfform! <form:select id="myField" options="myValue" value="somethingelse"/> (that's from my form custom tag library, not yet released) :) ----- Excess quoted text cut - see Original Post for more -----
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||