Closed dmlond closed 1 year ago
Believe you need to call to_json.html_safe
when setting the value. Either way, all of this is usage questions, not a bug. Please use the Hotwire forum or Discord for usage help.
it seems like a bug to me. The handbook states that the 'Object' type is decoded as JSON.parse(value). But the value I am passing into the value of type String can be turned into an object by passing it through JSON.parse(value), but the same value does not work with a value of type Object. This is true with or without html_safe.
I am using stimulus-rails version 1.2.1
I have 2 Plain Objects that include ActiveModel::Serializers::JSON.
I would like to pass an instance variable @switchers that contains an Array of Switcher objects into a Stimulus Controller as a value of type Object.
I have tried the following in my views
This ignores the ActiveModel::Serializers::JSON entirely and renders the entire object with its class name, which causes a JSON.parse error when the stimulus controller is loaded.
console output (truncated)
the DOM looks like this
I tried to use to_json
This results in the following error in the console
The rendered DOM element looks ok to me, except some html escapes that are sent in
But if I change the value type to String, and use JSON.parse on the value, it gives me the expected object.
What is the expected behavior?