Wrong dataset getting from Docs example
loqimean opened this issue · comments
Bug Report
Please help us help you by filling out any applicable information in this template and removing the rest!
Describe the bug
I copied code from an example in docs and have a bug that code from an example gives me a nil value, so, solutions is to use code like bellow, but as I now it's wrong way:
class CounterReflex < ApplicationReflex
def increment
@count = element.dataset.dataset["data-count"].to_i + element.dataset.dataset["data-step"].to_i
end
end
To Reproduce
Just use code from docs to create a CounterReflex
using an importmaps and rails 7
Expected behavior
Expected working example from docs
Screenshots or reproduction
Versions
StimulusReflex
- Gem:
3.4.1
- Node package:
14.17.6
External tools
- Ruby:
3.1.2
- Rails:
7.0.5
- Node:
14.17.6
Browser
- Browser
chrome
- Version
103.0.5060.53
Hey @loqimean, looking at your CounterReflex
class and the docs it seems like that there is a slight disconnect.
This should work:
class CounterReflex < ApplicationReflex
def increment
@count = element.dataset.count.to_i + element.dataset.step.to_i
end
end
Also please make sure you are using the latest StimulusReflex 3.5.0.rc2
version to make sure we get the latest and best version of StimulusReflex, which is also optimized for Rails 7 and Importmaps.
Let us know if that works for you and feel free to re-open the issue if not. Thank you!
Alternatively here's a list of all the accessors that work on element
:
https://docs.stimulusreflex.com/guide/reflex-classes.html#element