3

I want to pass the value of an input field from the view to the controller. What's the best way to achieve this without binding the input field to a property of the model? Example:

view:

<form data-event-submit="searchHero">
    <input type="text" placeholder="Name..." data-bind="myquery"/>
</form>

controller:

searchHero: ->
    console.log myquery
shoen
  • 11,845
  • 4
  • 22
  • 27
  • I'm having a similar issue. It feels like the ``params`` object in Batman is useless for anything but named route parameters. Using data bindings for arbitrary search/form inputs just doesn't feel right. I wish there was an easy way to get form input values into the params object easily. – richoffrails Oct 26 '12 at 18:36

1 Answers1

1

Actually, this code binds the input's contents to the myquery prop of the controller, so you can access it via standard batman's get:

searchHero: ->
  console.log @get 'myquery'
nl_0
  • 391
  • 1
  • 6
  • Yep, this is how I'd do it too. You're setting an attribute of the controller when you call: `@get('myQuery')` or `@set('myQuery', 'lol omg')`. The view has access to attributes of the controller, so that view binding will bind itself to the same attribute! – rmosolgo Nov 19 '13 at 05:54