Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Controller : "TypeError: _ref16 is undefined" #12

Open
magpieuk opened this issue Feb 1, 2022 · 5 comments
Open

Extending Controller : "TypeError: _ref16 is undefined" #12

magpieuk opened this issue Feb 1, 2022 · 5 comments
Labels
question Further information is requested

Comments

@magpieuk
Copy link

magpieuk commented Feb 1, 2022

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
Copy link
Author

magpieuk commented Feb 1, 2022

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

@guillaumebriday
Copy link
Member

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

Is this related?

@guillaumebriday guillaumebriday added the question Further information is requested label Feb 4, 2022
@magpieuk
Copy link
Author

magpieuk commented Feb 4, 2022

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
Copy link
Author

magpieuk commented Feb 4, 2022

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

@antonysastre
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants