Skip to content Skip to sidebar Skip to footer

Javascript: Using A Method From Model In Javascript Code

I am trying to set up users on an asset, and I am running into the problem of not being sure how to pass my max_users method from asset.rb to my JS code. I am trying to use the max

Solution 1:

Had to retrieve the value of max_users, and convert it into an integer. Then just plugged it in so that if the amount of fields showing up was greater than, or equal to, the max_users, the form would stop generating new fields.

$ ->
  check_to_hide_add_link = ->
    max_users = parseInt($("#asset_max_users").val(), 10)
    if $("#assets_users .nested-fields").length >= max_users
      $("#assets_users .links a").hide()
    else
      $("#assets_users .links a").show()

  $("#assets_users").bind "cocoon:after-insert", ->
    check_to_hide_add_link()

  $("#assets_users").bind "cocoon:after-remove", ->
    check_to_hide_add_link()

  check_to_hide_add_link()

Post a Comment for "Javascript: Using A Method From Model In Javascript Code"