Giter Site home page Giter Site logo

Comments (16)

mbest avatar mbest commented on July 18, 2024

That's because the input field is actually removed and re-created after being dropped in the new location.

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

Is this accepted behavior? It seems like a significant issue to me. Is it commonly accepted that input fields shouldn't be part of a drag and drop scenario?

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

BTW, I came up with a workaround by having the input field bound to a property and forcing it to lose focus prior to the drag and dropping. In IE, it would lose its value even with a binding.

However, this workaround is a kludge, and doesn't work for non-bound input fields. So hopefully there will be a continued discussion about how it could be fixed in the library. Maybe not recreating the sorted item each time?

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

Hi @johnwest80
Can you describe your scenario a little bit further? In a typical KO app, you would have the input bound to an observable or property on your view model, so it would be represented in your data and naturally move with it as the items are sorted.

You may want to consider using valueUpdate: 'afterkeydown' to update the model as the user types.

The sortable binding works by moving the items in the observableArray to their new location and allowing KO to re-render them properly.

Would be happy to discuss this further though and try to find the best solution for your app.

from knockout-sortable.

mbest avatar mbest commented on July 18, 2024

The only way I see this could be supported would be if sortable directly handled the DOM updates and synchronization.

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

It does work, mostly, with bound properties. But as my note above states, with IE (I tested IE9), if the input textbox still has focus when you drag, the updated value is lost after the drag action. Try the fiddle below in IE9, change a value, and, without tabbing out of the textbox, drag and drop it. The value will be lost. If you tab out first, the value is retained.

http://jsfiddle.net/hw9B2/27/

I did create a workaround by setting the focus to the window prior to the drag action, but anytime there's a hack to make things work, it seems like it's an opportunity to fix the problem at the source instead :).

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

I would not be opposed to adding something to the plugin to help with that particular issue (make sure field loses focus first). Using valueUpdate: 'afterkeydown' would be a choice as well, but that might not be appropriate for certain scenarios.

Although I can kind of see how it could work, I am not really in favor of having the plugin be responsible for the DOM synchronization itself.

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

I can see your point about not doing the full DOM sync. I just added a sortable option as shown below to set focus to the window at the start of the operation. I'm not well-versed on events, so there's probably a better/more recommended way.

data-bind="sortable: {data: Policies, afterMove: updateMonthAfterMove, options: { start: function() {window.focus();} } }"

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

@johnwest80 my thought was to add a start handler similar to what you have in the plugin itself.

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

So we'd still have to add a start function to set focus to the window ourselves, but it'd be at your library level instead of having to set options on jquery ui? Or would you bake in the window.focus yourself somehow?

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

No, I would pass a start handler (that sets focus) in as an option when the plugin initializes jQuery UI's sortable so it would just work without any additional configuration.

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

The plugin now moves the focus automatically in the start function and wraps any start/update functions that are passed in as options now.

from knockout-sortable.

johnwest80 avatar johnwest80 commented on July 18, 2024

I'm still having the same issue in Firefox. It happens on your sample, too. Add a new, change the value, then drag it. The value will revert to "New".

http://jsfiddle.net/rniemeyer/hw9B2/

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

@johnwest80 - I'll take another look at this one when I get a chance and see what it takes to get FF to apply the change.

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

@johnwest80 it now fires the change event on the focused input. This seems to work fine across browsers.

from knockout-sortable.

rniemeyer avatar rniemeyer commented on July 18, 2024

Let me know if you see any additional issues.

from knockout-sortable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.