ColdFusion Ajax Bindings - Form Fields only?

Jose asks:

I just got started using cfdiv an the other AJAX related tags and I have a question about passing params in the bind attribute. I have the following test code: <cfinput name="EmployeeID" type="hidden" value="#variables.EmployeeID#" />

<cfgrid name="goals" format="html" striperows="yes" bind="cfc:ab.model.goals.goalsGateway.getGoalsGridRecordSet(page={cfgridpage}, pagesize={cfgridpagesize}, gridSortColumn={cfgridsortcolumn}, gridSortDirection={cfgridsortdirection}, EmployeeID={EmployeeID})">

Does it mean I can only pass filter params for the cfcs I am using thru having those hidden "pass thru" fields? What I am missing?

The short answer is yes. Bindings allow you to speak to JavaScript, CFCs, and vanilla URLs, and they allow you to automatically monitor values of form fields. (As well as events.) But it doesn’t mean you have to use a hidden form field as you have here. You could have simply hard coded the value like so:

bind=”cfc:ab.model.goals.goalsGateway.getGoalsGridRecordSet(page={cfgridpage}, pagesize={cfgridpagesize}, gridSortColumn={cfgridsortcolumn}, gridSortDirection={cfgridsortdirection}, EmployeeID=#variables.employeid#)”

Note when I say ‘hard coded’, what I mean is that the value is still dynamic (see the #s?) but it isn’t a client side bound variable.

Just to be clear - this doesn’t mean that ColdFusion’s Ajax support can only work with form fields. It’s just that the bindings to allow for automatic updates are tied to form fields. (And Spry datasets as well, but that’s another story.) You can still easily call server side code using cfajaxproxy for example, and pass anything you want, but this does mean you have to write a few lines of JavaScript.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments