I`m trying to add autocomplete to a field that is included in a partial view in a Rails 3 app.
I can`t tell JQuery to look for it via form name, since a random attribute is generated every time the field is rendered.
Here’s rundown of the code:
cardio_exercises.js.coffee
jQuery ->
$('input.Cardio').autocomplete
source: ['Elliptical trainer','Stair stepper (Stairmaster)','Stationary or recumbent bike','Jacob`s ladder','Arm ergometer (arm cycle)','Rowing machine','Treadmill walking','Treadmill running','Kettlebells','Interval training','Box jumps','Step ups','Plyometrics','Cycling','Jogging','Running','Power walking','Swimming','Water jogging/running','Bleacher running','Spinning','Step aerobics','Walking the dog','Playing with your dog','Taking the stairs','Jumping jacks']
In the partial I added a class of Cardio to the input field:
_cardio_exercise_fields.html.erb
<table>
<tr>
<td>
<b>Exercise Name</b><br>
<%= f.text_field :exercise_name, :class => 'Cardio' %></td>
<td>
<b>Duration</b><br>
<%= f.text_field :duration %> minutes
</td>
</table>
I have no clue about JS/jQuery so I would appriaciate any advice on the matter.
I know that it works (autocomplete) in normal views, just not in the partial in trying to implement it in.
jQuery works normally in Rails3, I mean, once the page is rendered,
I suggest you install the firebug and watch the error message from its console.
( or developer tool in chrome & safari)