Re: [cfwheels] Re: Select tag custom attributes for options

383 views
Skip to first unread message

Chris Peters

unread,
Dec 9, 2011, 9:04:28 AM12/9/11
to cfwh...@googlegroups.com
You have a couple options:

1. Don't use selectTag() because it's only intended for basic key/value stuff. Create your own partial instead.

2. Create a helper method called somethingSelectTag() and pass it the data. In it, call selectTag with what you want for value/text, then use Replace() to add in extra attributes to the <options>.

<cffunction name="somethingSelectTag">
    <cfset local.selectTag = selectTag(name=arguments.name, options=arguments.options, textField="column1", valueField="column2")>
    
    <cfloop query="arguments.options">
        <cfset local.selectTag = Replace(local.selectTag, 'value="#arguments.options.column2#"', 'data-something-else="#arguments.options.column3#" value="#arguments.options.column2#"')>
    </cfloop>

    <cfreturn local.selectTag>
</cffunction>

On Thu, Dec 8, 2011 at 5:33 PM, Zach L <zplesp...@gmail.com> wrote:
Thanks for the suggestion, but I'm not sure if structs can help me.

From what I understand, with the struct, I can only pass the key value
and the option's text field, right? What I'm looking for is a way to
populate the option's value and text fields, and then store additional
information in custom attributes.

For example, let's say I had a database table with three columns, I
want column 1 to be the value, column 2 to be the text for the option,
and I want to store column 3 as an attribute that I can access later
with JavaScript.

It doesn't need to be in a custom attribute, but I'm not very familiar
with structs, so I can't figure out how I could use it to pass all
three values to an option without combining two values into a
delimited string and separating it later when I want to use it.

What I have now is something like this:

#selectTag(name="name", options=foo, valueField="column1",
textField="column2", data_info=foo.column3)#

Which doesn't work because it only applies the data_info attribute to
the select tag, not the options.

Also, I apologize if my original question was too vague to know what I
was looking for.

Any ideas? Thanks

On Dec 8, 1:13 pm, Mohamad El-Husseini <husseini....@gmail.com> wrote:
> Do you have to use custom data tags? If not, you pass the selectTag() a
> list of options in key value pairs (using a struct):
>
> #selectTag(name="name", options={ 1 = "Option one", 2 = "Option 2" })#
>
> You can also set this struct up in your controller if you prefer and pass
> it as a variable. This will result in the following HTML:
>
> <option value="1">Option one</option>
>
> It's not a custom data attribute, but it does allow you to pass extra data.
> The struct key can be a string. It doesn't have to be numeric.

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


Zach L

unread,
Dec 8, 2011, 3:51:46 PM12/8/11
to ColdFusion on Wheels
I've been using Cfwheels for about a month now and loving it. Today I
came across a problem that I can't seem to figure out, so I though I'd
ask the discussion group!

Okay, so I'm using the CfWheels "selectTag()" function to generate a
list, and what I want to do is store a little more information using
custom attributes on each of the options.

Here's what I've tried:

#selectTag(name="name", options=foo, data_info=foo.bar)#

This adds the attribute "data_info" to the select tag. I want to add
the data to each of the options instead. Is there a way to do this?

I want similar to this:

<select>
<cfloop query="foo">
<cfoutput><option data-short="#foo.bar#">Text</option></cfoutput>
</cfloop>
</select>

Any help?

Thanks in advance,

-Zach L

Mohamad El-Husseini

unread,
Dec 8, 2011, 4:13:02 PM12/8/11
to cfwh...@googlegroups.com

Zach L

unread,
Dec 8, 2011, 5:33:23 PM12/8/11
to ColdFusion on Wheels
Thanks for the suggestion, but I'm not sure if structs can help me.

From what I understand, with the struct, I can only pass the key value
and the option's text field, right? What I'm looking for is a way to
populate the option's value and text fields, and then store additional
information in custom attributes.

For example, let's say I had a database table with three columns, I
want column 1 to be the value, column 2 to be the text for the option,
and I want to store column 3 as an attribute that I can access later
with JavaScript.

It doesn't need to be in a custom attribute, but I'm not very familiar
with structs, so I can't figure out how I could use it to pass all
three values to an option without combining two values into a
delimited string and separating it later when I want to use it.

What I have now is something like this:

#selectTag(name="name", options=foo, valueField="column1",
textField="column2", data_info=foo.column3)#

Which doesn't work because it only applies the data_info attribute to
the select tag, not the options.

Also, I apologize if my original question was too vague to know what I
was looking for.

Any ideas? Thanks

On Dec 8, 1:13 pm, Mohamad El-Husseini <husseini....@gmail.com> wrote:

tpet...@gmail.com

unread,
Dec 9, 2011, 12:03:23 PM12/9/11
to ColdFusion on Wheels
why not just use a client side library like jquery to accomplish this.
why does it have to be done on the server end?

Zach L

unread,
Dec 12, 2011, 10:39:43 AM12/12/11
to ColdFusion on Wheels
@Chris:

Thanks for your suggestions! I decided to throw together a partial for
now. If I find that I reuse the code a lot I'll probably end up making
a more modular helper function like you suggested.

Thanks again to everybody for your suggestions.

> >http://groups.google.com/group/cfwheels?hl=en.- Hide quoted text -
>
> - Show quoted text -

Joel Stobart

unread,
Sep 8, 2015, 11:04:16 AM9/8/15
to CFWheels
Hi Guys,

I think now data attributes have become ubiquitous it would be great if the query fields could be output as data attributes from a select. 

I could have used it a few times in recent days


        #select(

                objectName="product", property="countryId",

                label="Country of Manufacture",
includeBlank="Select Country",

options=model("country").findAll(order="iseea DESC, name ASC"), valueField='id', textField='name'


                                )#


Chris Peters

unread,
Sep 8, 2015, 11:58:09 AM9/8/15
to cfwh...@googlegroups.com
Your code snippet doesn't really show us what you were intending to do.

I also would find it troubling that CFWheels would set data attributes by default. That would be an unfortunate way for a developer to unintentionally put sensitive data into HTML markup without realizing it.

If you have any ideas on what the CFWheels API would look like to opt-in to data attributes with query data, I would be all ears.

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.

To post to this group, send email to cfwh...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfwheels.
For more options, visit https://groups.google.com/d/optout.



--

Chris Peters
Web Developer
Liquifusion Studios

chris....@liquifusion.com
Skype: liquifusion.support
www.liquifusion.com
Reply all
Reply to author
Forward
0 new messages