0

I hope to explain this in simplest way possible but if something is unclear please let me know.

I'm using AngularJS UI-Sortable for drag and drop functionality on a project. Everything is working fine from drag and drop perspective. It takes the item it clones it in the dropable area as expected.

But the issue that I'm having is when the item is dropped I want to allow the user to edit the text.

    <div id="main_page" ui-sortable="sortableOptions" class="drop-area connected-drop-target-sortable" ng-model="selectedComponents">
    <div ng-repeat="component in selectedComponents track by $index" class="eq-height">
        <a href="#" group="content">
            <div class="element">

               <!-- Heading - Affected area -->
               <div class="component" ng-if="component.title == 'Heading'" ng-init="editing = false">
                  <input class="heading" ng-blur="editing = false" ng-hide="!editing" type="text" placeholder="Heading" ng-model="component.element" />
                  <h2 ng-click="editing = true" ng-hide="editing" ng-bind-html="component.element">{{component.element}}</h2>
               </div>

            </div>
        </a>
    </div>
</div>

That part works fine too. But if I drop the second heading or more two way binding updates all Headings that were dropped.

So then I thought maybe I need to pass $index in ng-model so angular knows which one is being updated as such:

<div id="main_page" ui-sortable="sortableOptions" class="drop-area connected-drop-target-sortable" ng-model="selectedComponents">
        <div ng-repeat="component in selectedComponents track by $index" class="eq-height">
            <a href="#" group="content">
                <div class="element">

                   <!-- Heading - Affected area -->
                   <div class="component" ng-if="component.title == 'Heading'" ng-init="editing = false">
                      <input class="heading" ng-blur="editing = false" ng-hide="!editing" type="text" placeholder="Heading" ng-model="component.element[$index]" />
                      <h2 ng-click="editing = true" ng-hide="editing" ng-bind-html="component.element[$index]">{{component.element[$index]}}</h2>
                   </div>

                </div>
            </a>
        </div>
    </div>

But unfortunately that did not have any affect. Here is an image of the issue if its any help. Ui Sortable Two way binding issue

3
  • Can you provide jsfiddle? Commented Mar 16, 2016 at 10:47
  • Sorry because this is client work and lot of branding etc involved I'm unable to post it in jsfiddle. My employer would not allow that Commented Mar 16, 2016 at 10:57
  • We need work example for reproduce your problem. Commented Mar 16, 2016 at 12:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.