Skip to main content
Inspiring
July 14, 2009
Answered

Anyone know what bindattribute does in CFINPUT and CFSELECT?

  • July 14, 2009
  • 2 replies
  • 2764 views

G'day

Now... <cfinput> and <cfselect> have this bindattribute attribute.  The docs say this:

Specifies the HTML tag attribute whose value is set by the bind attribute. You can only specify attributes in the browser’s HTML DOM tree, not ColdFusion-specific attributes.

Right.  Lovely.

So what's that all about then?  Anyone have any ideas?  Anyone got some demo code that shows it in action in a meaningful way?

Cheers.

--

Adam

(Ian, I see you've remained pretty busy here in my absence 😉

This topic has been closed for replies.
Correct answer BKBK

My understanding is that the attribute bindAttribute works only for HTML forms, the default format for cfform. It is applicable only for the fields <cfinput type="text">, <cftextarea> and <cfselect>, and the field must  have a value for the bind attribute. Otherwise, Coldfusion ignores the value of bindAttribute.


To me, it only makes sense if the possible values of bindAttribute are the names of those properties of the DOM Input Text Object, DOM Textarea Object and DOM Select Object, respectively, for which we can actually observe any dynamic changes. For example,


bindAttribute="value"(default, when 'bind' attribute defined, but no 'bindAttribute')
bindAttribute="size"
bindAttribute="name"
and so on.


It wouldn't make sense otherwise, would it? At least, that's my take on it.

The examples below involve <cfinput>. You can work out similar examples for <cftextarea> and <cfselect> yourself.

<cfif isDefined("form.sbmt")>
<cfdump var="#form#">
</cfif>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text" size="37" myCustomAttr="BKBK's test">
<br>
<!--- Here, bind is defined and bindAttribute is not. So bindAttribute takes on the default value, namely, 'value'. The result of evaluating the bind expression dynamically becomes the value of field2a  --->
Field 2a: <cfinput name="field2a" bind="{field1.myCustomAttr}" type="text">

<!--- equivalent to: --->

<!--- Field 2a: <cfinput name="field2a" bind="{field1.myCustomAttr}" type="text" bindAttribute="value"> --->

<br>
<!--- Here, the expression {field1} is, by default, the same as {field1.value}  --->
Field 2b: <cfinput name="field2b" bind="{field1}" type="text">

<!--- equivalent to: --->

<!--- Field 2b: <cfinput name="field2b" bind="{field1.value}" type="text" bindAttribute="value"> --->
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text" size="37">
<br>
<!--- Here, the value of bindAttribute is 'size'. The size of field3 changes dynamically to that of field1  --->
Field 3: <cfinput name="field3" bind="{field1.size}" type="text" bindAttribute="size">
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text">
<br>
<!--- Here, the value of bindAttribute is 'name'. The name of the field changes dynamically from 'field4' to 'id1'. You can see that when the form is submitted  --->
Field 4: <cfinput name="field4" bind="{field1.id}" type="text" bindAttribute="name">
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

2 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
August 15, 2009

My understanding is that the attribute bindAttribute works only for HTML forms, the default format for cfform. It is applicable only for the fields <cfinput type="text">, <cftextarea> and <cfselect>, and the field must  have a value for the bind attribute. Otherwise, Coldfusion ignores the value of bindAttribute.


To me, it only makes sense if the possible values of bindAttribute are the names of those properties of the DOM Input Text Object, DOM Textarea Object and DOM Select Object, respectively, for which we can actually observe any dynamic changes. For example,


bindAttribute="value"(default, when 'bind' attribute defined, but no 'bindAttribute')
bindAttribute="size"
bindAttribute="name"
and so on.


It wouldn't make sense otherwise, would it? At least, that's my take on it.

The examples below involve <cfinput>. You can work out similar examples for <cftextarea> and <cfselect> yourself.

<cfif isDefined("form.sbmt")>
<cfdump var="#form#">
</cfif>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text" size="37" myCustomAttr="BKBK's test">
<br>
<!--- Here, bind is defined and bindAttribute is not. So bindAttribute takes on the default value, namely, 'value'. The result of evaluating the bind expression dynamically becomes the value of field2a  --->
Field 2a: <cfinput name="field2a" bind="{field1.myCustomAttr}" type="text">

<!--- equivalent to: --->

<!--- Field 2a: <cfinput name="field2a" bind="{field1.myCustomAttr}" type="text" bindAttribute="value"> --->

<br>
<!--- Here, the expression {field1} is, by default, the same as {field1.value}  --->
Field 2b: <cfinput name="field2b" bind="{field1}" type="text">

<!--- equivalent to: --->

<!--- Field 2b: <cfinput name="field2b" bind="{field1.value}" type="text" bindAttribute="value"> --->
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text" size="37">
<br>
<!--- Here, the value of bindAttribute is 'size'. The size of field3 changes dynamically to that of field1  --->
Field 3: <cfinput name="field3" bind="{field1.size}" type="text" bindAttribute="size">
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

<cfform action="#cgi.SCRIPT_NAME#">
Field 1: <cfinput name="field1" id="id1" type="text">
<br>
<!--- Here, the value of bindAttribute is 'name'. The name of the field changes dynamically from 'field4' to 'id1'. You can see that when the form is submitted  --->
Field 4: <cfinput name="field4" bind="{field1.id}" type="text" bindAttribute="name">
<br>
<cfinput name="sbmt" value="test it" type="submit">
</cfform>

Inspiring
August 26, 2009

Brilliant, thanks mate.

--

Adam

August 11, 2009

Hello A Cameron

Please go through following link

     http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001396.htm

Regards

Kunjan

Inspiring
August 11, 2009

Hi Kunjan, thanks for that.

I think you might have misread my question.  I was not asing about the bind attribute, I was asking about the bindattribute attribute.

--

Adam