I’m trying to use the HTMLHelper to unify the look and feel of all my forms, seems like a good idea huh? My experience with HTMLHelpers is based on the CFWheels one.
But the select function seems to have an omission, unless i’m not seeing it. Can i pass a list of options, and include a blank, OR pass a list of options and their values?
I could try building a query to hold this list but there’s really only 3 or 4 items, and to be honest, it’s just going to be easier to not use the HTMLHelper for selects!
Also, whilst i’m here, I’m applying global wrappers to all of the fields, so what i’ve done is update the HTMLHelper cfc to remove all default="" from anything which then calls inputField(), and setting the defaults in that function. This seems kinda hacky to me, is there a way to pass global defaults somewhere else? Config.cfc, or something, maybe?
If this is the best solution, i’m def going to submit this slightly changed version as a pull request, because there’s no reason to set an empty string default twice!
Apologies if i’m just using it incorrectly!
Alex, yes the values attribute holds that information.
Not sure I understand what you are saying in the last part, are you saying you removed the default="" from the inputField? If any argument is not required, there needs to be something as a default. Can you give an example of what you mean?
I’ll give that a go, there is no values argument specified on the select function, and as far as i could tell the Options function wouldn’t accept both values and names either! I guess i’ve done too much looking, not enough trying!
Also, re: the second point. Arguments like GroupWrapper get given a default in two places, firstly in textField(), which just calls InputField(), and again within InputField().
I want everything which uses inputField() to have the same default classes & wrappers. But, if i set a default (for GroupWrapper or something else) in InputField() it doesn’t get used, because it’s being passed the default of “” from textField().
By removing the default="" from textField() it now has no value for GroupWrapper, so the inputField() default gets used.
Ok, so what i’ve landed on is this:
<cfset listOfStatuses = ‘Reserved,Sent,Received,Sold>
#html.Select(name=“status”,label=“Status:”, options=html.options(’- Any - ,#listOfStatuses#’,"’’,#listOfStatuses#"))#
I’ve had to create the list as a var, and pass it through in two locations, whilst calling a function within a function.
Which is kinda messy right? Isn’t there an easier way of just adding a blank row at the top of options? Surely that’s a common enough thing, right?
If this is the accepted workaround, i can’t see myself going to all that effort!
Also, if this was coming from a query rather than a simple list, there’s no way for me to insert a blank option either.
Hey Alex, here’s a simple one-liner you could use for that query, if needed. (Not tested, but should work)
<cfset listOfStatuses = ListPrepend(ValueList(query.column),’- Any -’) />
Thanks Don, that will solve that one minor case.
So, i’m guessing the consensus out there is the Select Helper doesn’t do enough of what i need it to.
In case i’m wrong, as an example, i would love to know how people would use the htmlHelper Select to output this:
-- Select template --
Especially, as i don’t believe html.options() will allow me to pass in references to entity getters, right?
Sorry to keep going on about this, but I really don’t want to have to output select boxes in a different way to every other field. Especially as i don’t think i’m doing anything outside the norm here. Has anyone ever found select() useful?
you can extend the htmlhelper and overwrite that function.
Sorry, I’ve barely used the HTMLHelper. I’d say there’s probably room for improvement for sure. Put in a ticket for how you’d like it to work, or better yet put in a pull request!
ColdBox Platform Evangelist
Ortus Solutions, Corp
ColdBox Platform: http://www.coldbox.org