stimulus-sortable
stimulus-sortable copied to clipboard
Extending Controller : "TypeError: _ref16 is undefined"
Following the example of the "Extending Controller" in the documentation I am getting an error "Uncaught (in promise) TypeError: _ref16 is undefined"
Any ideas?
I am trying to get a hidden position input to be set to the correct index when items are moved, but falling at the first hurdle.
Looks like the end() function has changed. If I use the following then it seems to work:
import Sortable from "stimulus-sortable"
export default class extends Sortable {
end ({ item, newIndex }) {
super.end({ item, newIndex })
console.log(item)
}
}
Yeah the end function has changed and the package moved to Stimulus 3.
Is this related?
This is what I cam up with in the end which works although it could do with a bit of refining:
import Sortable from "stimulus-sortable"
export default class extends Sortable {
end ({ item, newIndex }) {
super.end({ item, newIndex })
var elems = item.parentElement.getElementsByClassName("position_hidden_field")
for (var i = 0; i < elems.length; i++) {
elems[i].value = i + 1
}
}
}
I think the docs just need updating to show the correct code to use to extend.
Added a pull request #45 with docs update, not sure if I followed proper contributor policies.