werein / x-editable-rails

Edit fields easily with X-Editable helper

Home Page:https://wereinhq.com/guides/x-editable-rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reset X-editable class after save

stopachka opened this issue · comments

I'm using x-editable to allow the user to associate itself to another model. The styling changes based on what type of model the user is associated to.

Right now, it works, but the css class only changes after I refresh the page.

How would I go about resetting the css class, after x-editable saves the new value?

This is how my input looks like ->

== editable user, :heat_id, url: admin_user_path(user), type: "select", value: (user.heat.level if user.heat), source: Heat.all.map{ | heat | {value: heat.id, text: heat.level} }, class: "#{user.heat.badge if user.heat}"

I'd essentially need to reapply

class: "#{user.heat.badge if user.heat}"

Hi, that's could be possible done with respond to javascript.

You can find more info here:
http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html

Hi Jiri, thanks for the link to the resource. Will research into it, and update this post with the solution I find.

Cheers

Ahh, looks like x-editable had this built right in! You can put a custom classes data-field.

This is what I did --

 == editable user, :heat_id, url: admin_user_path(user), type: "select", value: (user.heat.level if user.heat), source: Heat.all.map{ | heat | {value: heat.id, text: heat.level} }, classes: Hash[Heat.all.map{ | heat | [heat.id, heat.badge]}], class: "#{user.heat.badge if user.heat}"