Skip to content

Cater for possibility of el not existing #982

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

Merged
merged 3 commits into from
Jul 16, 2015
Merged

Cater for possibility of el not existing #982

merged 3 commits into from
Jul 16, 2015

Conversation

fergaldoyle
Copy link
Contributor

While writing a drag and drop vue sortable directive which uses jQuery UI sortable (both same list and connected list sortable), I found vue was throwing el undefined errors a lot with various actions, e.g. dragging the first item in a list then updating the underlying array model. The element had been removed by jQuery while vue was expecting it to exist.

By checking for the existance of el, and returning and empty object if it does not exist, allow these two dom manipulation libraries play nicely together.

@yyx990803
Copy link
Member

This will likely cause the list to go out of sync. I need to see a demo of jQuery UI sortable working properly with this change.

@fergaldoyle
Copy link
Contributor Author

Here is the sortable directive with stock vue.js (throws errors)
http://jsfiddle.net/fergal_doyle/5Lrtte9v/7/

And here is the same directive but with a built of vue.js including the change I made in this PR:
http://jsfiddle.net/fergal_doyle/5Lrtte9v/6/

You can drag and drop items, use methods to reverse and add items to the model in any combination and the list stays in sync.

@@ -683,6 +683,9 @@ module.exports = {

function findPrevVm (vm, anchor, id) {
var el = vm.$el.previousSibling
if (!el) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally got time to investigate this and it seems to indeed work! One thing here is that we can just if (!el) return, no need for the empty object.

@fergaldoyle
Copy link
Contributor Author

I've made the changes, no empty object now being returned.

yyx990803 added a commit that referenced this pull request Jul 16, 2015
Cater for possibility of el not existing
@yyx990803 yyx990803 merged commit 71329c3 into vuejs:dev Jul 16, 2015
@yyx990803
Copy link
Member

Thanks!

yyx990803 pushed a commit that referenced this pull request Sep 10, 2015
Cater for scenario where there is no previous sibling of el. Solution to #1249 and similar to #982. Occurs in scenario where dragging between lists using a library such as RubaXa Sortable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants