stimulus-sortable icon indicating copy to clipboard operation
stimulus-sortable copied to clipboard

Extending Controller : "TypeError: _ref16 is undefined"

Open magpieuk opened this issue 2 years ago • 5 comments

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.

magpieuk avatar Feb 01 '22 14:02 magpieuk

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)
    }
}

magpieuk avatar Feb 01 '22 14:02 magpieuk

Yeah the end function has changed and the package moved to Stimulus 3.

Is this related?

guillaumebriday avatar Feb 04 '22 08:02 guillaumebriday

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
        }

    }
}

magpieuk avatar Feb 04 '22 09:02 magpieuk

I think the docs just need updating to show the correct code to use to extend.

magpieuk avatar Feb 04 '22 09:02 magpieuk

Added a pull request #45 with docs update, not sure if I followed proper contributor policies.

antonysastre avatar Feb 16 '22 17:02 antonysastre