August 30, 2005

make cfselect your sock puppet

i had the need to keep a cfselect synched up w/other cfform objects like grids and trees that were being changed by user inputs (managing IMAP mail folders for instance). digging around the flex docs again, it seems cfselect is part of the mx.controls.listclasses package and you can indeed manipulate it quite a bit using that package's DataSelector/DataProvider class methods. for me the interesting methods were:
  • getItemAt()
  • removeItemAt()
  • addItemAt()
  • replaceItemAt()

and the selectedIndex property. you can do a lot with a bit of action script:

<cfform name="testForm" format="Flash">
<cfselect name="test" size="1" visible="Yes" enabled="Yes" width="200">
<cfoutput>
<cfloop index="i" from="1" to="10">
<option value="#i#">test #i#</option>
</cfloop>
</cfoutput>
</cfselect>
<cfinput type="Button" name="a" value="length" visible="Yes" enabled="Yes"
   onclick="alert(test.length);">

<cfinput type="Button" name="b" value="get at 5" visible="Yes" enabled="Yes"
   onclick="alert('value@5: '+test.getItemAt(4).data);">

<cfinput type="Button" name="c" value="remove at 5" visible="Yes" enabled="Yes"
   onclick="test.removeItemAt(4); alert('removed');">

<cfinput type="Button" name="d" value="add at 5" visible="Yes" enabled="Yes"
   onclick='test.addItemAt(4,"newer test",5);alert("added");'>

<cfinput type="Button" name="e" value="change at 5" visible="Yes" enabled="Yes"
   onclick='test.replaceItemAt(4,"replaced item",5); alert("replaced");'>

<cfinput type="Button" name="f" value="select at 5" visible="Yes" enabled="Yes"
   onclick='test.selectedIndex=4; alert("selected");'>

</cfform>


and an update on the illegal ActionScript error, you can't use any of the restricted keywords even in AS comments. "//new delete" will also throw that error.

0 Comments:

Post a Comment

<< Home