Skip to content

Commit 52e3209

Browse files
committed
Amend element description to be correct
@nerdoc pointed out that the element documentation was wrong in #122, so this updates the documentation to the current behaviour.
1 parent 695ee72 commit 52e3209

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/reflexes.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ StimulusReflex makes the following properties available to the developer inside
6060
* `request.post` - If the page contains a form, this will find the closest form.
6161
* `session` - the Django session store for the current visitor
6262
* `url` - the URL of the page that triggered the reflex
63-
* `element` - a dictionary like object that represents the HTML element that triggered the reflex
63+
* `element` - an object that represents the HTML element that triggered the reflex
6464
* `params` - Contains the form parameters for the closest form
6565

6666
## Methods
@@ -74,7 +74,7 @@ StimulusReflex makes the following properties available to the developer inside
7474

7575
### `element`
7676

77-
The `element` property contains all of the Reflex controller's [DOM element attributes](https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) as well as other properties like, `tagName`, `checked` and `value`.
77+
The `element` property contains all of the Reflex controller's [DOM element attributes](https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) as well as other properties like, `tag_name`, `checked` and `value`.
7878

7979
{% hint style="info" %}
8080
**Most values are strings.** The only exceptions are `checked` and `selected` which are booleans.
@@ -98,17 +98,17 @@ from sockpuppet.reflex import Reflex
9898

9999
class ExampleReflex(Reflex):
100100
def work(self):
101-
self.element['id'] # the HTML element's id attribute value
101+
self.element.attributes # a dictionary that represents all attributes of the HTML element
102102
self.element.dataset # a dictionary that represents the HTML element's dataset
103103

104-
self.element['id'] # => 'example'
105-
self.element['tag_name'] # => 'CHECKBOX'
106-
self.element['checked'] # => 'true'
107-
self.element['label'] # => 'Example'
108-
self.element['data-reflex'] # => 'ExampleReflex#work'
109-
self.element.dataset['reflex'] # => 'ExampleReflex#work'
110-
self.element['data-value'] # => '123'
111-
self.element.dataset['value'] # => '123'
104+
self.element.attributes['id'] # => 'example'
105+
self.element.attributes['tag_name'] # => 'CHECKBOX'
106+
self.element.attributes['checked'] # => 'true'
107+
self.element.attributes['label'] # => 'Example'
108+
self.element.attributes['data-reflex'] # => 'ExampleReflex#work'
109+
self.element.dataset['reflex'] # => 'ExampleReflex#work'
110+
self.element.attributes['data-value'] # => '123'
111+
self.element.dataset['value'] # => '123'
112112

113113
```
114114
{% endtab %}

0 commit comments

Comments
 (0)