Comments (16)
That's because the input field is actually removed and re-created after being dropped in the new location.
from knockout-sortable.
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.
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.
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.
The only way I see this could be supported would be if sortable
directly handled the DOM updates and synchronization.
from knockout-sortable.
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.
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.
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.
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.
@johnwest80 my thought was to add a start
handler similar to what you have in the plugin itself.
from knockout-sortable.
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.
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.
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.
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.
@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.
@johnwest80 it now fires the change event on the focused input. This seems to work fine across browsers.
from knockout-sortable.
Let me know if you see any additional issues.
from knockout-sortable.
Related Issues (20)
- observableArray extended with deferred: true removes items from list HOT 2
- Draggable Incorrectly calls template init/update
- Using droppable next to a sortable
- Draggable Droppable Issue
- sortable dissapears after first drop HOT 4
- knockout-sortable not re-rendering when dragging to same index
- Sortable not working with latest jquery HOT 3
- Input and textarea cannot be selected in Firefox 40
- sortable behaviour inconsistent with droppable/draggable
- Confirmation popup before aftermove is executed HOT 1
- Sortable not working after upgrading to knockout 3.5 HOT 10
- anonymous templates will break in next version of knockout HOT 3
- droppable options drop event issue
- Does not work with knockout 3.5.0 HOT 2
- Problem after upgrading ko to 3.5.1 HOT 3
- Nested sortable support
- knockout-sortable drag and drop not working in Windows touch devices
- Get an error after clean data HOT 3
- JS error introduced by v1.2.1 "Fixed draggable and droppable disposal" HOT 1
- disableSelection on sortable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout-sortable.