Update input values for form live preview (Ruby on Rails)

I have a form with several inputs, for which I have live preview in Ruby on Rails app. Live preview works fine, until it comes to previewing form with existing record.

if my object is not created, I see something like this (note there is no “value” attribute)

<input class="deal_title" id="deal_title" name="deal[title]" type="text">

If I fill in the form and send it to the server, inputs “value”s attributes are being assigned with user-entered values, so if I open the form source I see:

<input class="deal_title" id="deal_title" name="deal[title]" type="text" value="New offer">

I have a script for bind live preview:

  $("#new_form input").keyup ->
    css_klass = $(this).attr("class")
    $(this).attr(value, $(this).val())
    inpt = $(this).val()
    $("." + css_klass + "_preview").html inpt

If I reproduce the same in JsFiddle, it works fine:

JsFiddle without “value”

JsFiddle with “value”

However in my Rails app, this only works in the first case (if no value is set). I use Rails 4 with turbolinks.


Download update.input.values.for.form.live.preview.ruby.on.rails.zip
Direct Link


Download


Download update.input.values.for.form.live.preview.ruby.on.rails.zip
Mediafire


Download


Download update.input.values.for.form.live.preview.ruby.on.rails.zip
Secureupload


Download


Download update.input.values.for.form.live.preview.ruby.on.rails.zip
Junocloud


Download


Download update.input.values.for.form.live.preview.ruby.on.rails.zip
EASY-SHARE


Download

Both comments and pings are currently closed.

Comments are closed.