Episodes
inopinatus PRO said over 3 years ago on Saving Individual Attributes with StimulusJS :
Thanks for this episode! You mentioned there are gems that will handle typing of attributes stored in JSON, and although it was out of scope for this episode I'm still interested - any suggestions for which gems to look at? Or could we somehow just use the attributes API?

Simon Kiteley PRO said over 2 years ago on Saving Individual Attributes with StimulusJS :
Don't know if it would be of any help to any one but I did this: ``` ``` and ``` switch_on(event) { let data = new FormData() // user[host_video] let that = this; data.append(this.off_switchTarget.name, '1') Rails.ajax({ type: 'PATCH', url: this.url(this.off_switchTarget), dataType: 'json', data: data, success: function (response) { var on = document.getElementById(that.element.getAttribute('id') + '-on'); var off = document.getElementById(that.element.getAttribute('id') + '-off'); on.style.display = 'inline'; off.style.display = 'none'; }, error: function (response) { console.log('Setting could not be saved.')} }) } switch_off(event) { let data = new FormData() let that = this; data.append(this.on_switchTarget.name, '0') Rails.ajax({ type: 'PATCH', url: this.url(this.on_switchTarget), dataType: 'json', data: data, success: function (response) { var on = document.getElementById(that.element.getAttribute('id') + '-on'); var off = document.getElementById(that.element.getAttribute('id') + '-off'); off.style.display = 'inline'; on.style.display = 'none'; }, error: function (response) { console.log('Setting could not be saved.')} }) } ``` Sure my javascript is pants and not my expertise but it works well.

Login to Comment