You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior: an alert is displayed with the following content: On click: this.$getElement(0) = BUTTON
Actual behavior: the content of the alert is wrong: On click: this.$getElement(0) = H1
HSP file
var klass = require("hsp/klass");
var Ctrl = klass({
// Uncomment the following line and the $getElement method will work fine:
// $refresh: function () {},
click: function () {
var expectedButton = this.$getElement(0);
alert("On click: this.$getElement(0) = " + expectedButton.tagName);
}
});
# template myCpt using c:Ctrl
<button onclick="{c.click()}">Click me</button>
# /template
# template main
<h1>Title</h1>
<#myCpt />
# /template
main().render("output");
Note
$getElement returns a correct value if there is a $refresh method in the controller.
This seems to be linked to the needCommentNodes variable in cptcomponent.js:
It is confusing to have a method which can return wrong values. If we do not want to always include comment nodes, it would be better to remove the $getElement method and to pass elements as parameters to $refresh, as discussed here
I already discussed that with @b-laporte , and apparently his initial plan was to only authorized the usage of $getElement() when you have a $refresh() implementation.
I was also thinking about dynamically adding that $getElement()method only when you define a $refresh() one.
For the solution regarding arguments, it can simply not be done like that. 😞 Just think about customisation, if you override a template, but keep the same controller, then your arguments might be different according to the changed template, and then you root element is different.
Plunk
Here is the plunk to reproduce the issue:
http://embed.plnkr.co/arLGKhwphORMRl9gmh1O
Click on the button.
Expected behavior: an alert is displayed with the following content:
On click: this.$getElement(0) = BUTTON
Actual behavior: the content of the alert is wrong:
On click: this.$getElement(0) = H1
HSP file
Note
$getElement
returns a correct value if there is a$refresh
method in the controller.This seems to be linked to the
needCommentNodes
variable in cptcomponent.js:It is confusing to have a method which can return wrong values. If we do not want to always include comment nodes, it would be better to remove the
$getElement
method and to pass elements as parameters to$refresh
, as discussed hereHashspace version
Tested with version 4491708.
The text was updated successfully, but these errors were encountered: