Issue in updating local model in angular xeditable
Asked Answered
R

2

12

I am trying to create a form , where one text field value depends on another text box.

With reference to angularjs, By default xeditable update local model after clicking save.But i would like to update the model instantly and show the updated value in another text box

<span editable-text="user.name" e-ng-model="user.name" e-name="name"></span>
<span editable-text="user.username" e-ng-model="user.username" e-name="username"></span>

I have enclosed the sample working code in jsfiddle

Retinitis answered 5/6, 2014 at 7:24 Comment(1)
ng-model value after clicking the save button is updatingCortex
E
3

@Pravin I think that I found a solution. I had the situation where I needs update the xeditable model when user select the dictionary entry on typeahead input. I was looking the solution and I found the following way:

<span editable-text="p.name" e-name="name" e-form="productForm" e-required
  e-typeahead="product as product.name for product in getProducts($viewValue) | filter:$viewValue | limitTo: 8"
  e-typeahead-editable="true" e-ng-maxlength="256" e-typeahead-focus-first="false"
  e-typeahead-on-select='onSelectProductFromDictionary($item, $model, productForm)'>
     {{ p.name }}
</span>

And the method which update the xeditable data:

    $scope.onSelectProductFromDictionary = function ($item, $model, form) {

        angular.forEach(form.$editables, function(editable) {
            if (editable.name === 'name') {
                return;
            }
            editable.scope.$data = $model.something; // this is a dictionary model
            editable.save(); // move the value from edit input to view xeditable value
            editable.hide(); // hide the specific xeditable input if you needs
        });

    };

I hope it helps.

UPDATE [JSFIDDLE]

https://jsfiddle.net/fLc2sdd2/

Exsanguinate answered 26/5, 2015 at 8:37 Comment(2)
Can you please include your solution in fiddle? @przemekRetinitis
I've added example fiddle. You can try select the state and then the username should change. You can experiment more ...Exsanguinate
C
1

Its updating

check this

Working Demo

html

<h4>Angular-xeditable Editable form (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
 <form editable-form name="editableForm" onaftersave="saveUser()">
    <div>
      <!-- editable username (text with validation) -->
      <span class="title">Name: </span>
      <span editable-text="user.name" e-ng-model="user.name" e-name="name" e-required>{{ user.name || 'empty' }}</span>
    </div> 

    <div>
      <!-- editable username (text with validation) -->
      <span class="title">User name: </span>
      <span editable-text="user.username" e-ng-model="user.username" e-name="username" e-required>{{ user.username || 'empty' }}</span>
    </div>
    <div>

      <!-- button to show form -->
      <button type="button" class="btn btn-default" ng-click="editableForm.$show()" ng-show="!editableForm.$visible">
        Edit
      </button>


      <!-- buttons to submit / cancel form -->
      <span ng-show="editableForm.$visible">
        <button type="submit" class="btn btn-primary" ng-disabled="editableForm.$waiting">
          Save
        </button>
        <button type="button" class="btn btn-default" ng-disabled="editableForm.$waiting" ng-click="editableForm.$cancel()">
          Cancel
        </button>
      </span>
                <br> {{user}}
    </div>
  </form>  
</div>
Cortex answered 5/6, 2014 at 7:36 Comment(3)
Thank you for your response. But what i am trying is , when i type value in text box1, it should update text box2 which contains model whose value depends on model1.Retinitis
that means while typing itself you want the data value to be changed within text box2Cortex
My ultimate aim is 3 steps. 1.type some thing in text box1. 2.based on text in textbox1 some function should be performed . 3.based on that it returns some value in text box2. Note: It should be done before clicking save button.Retinitis

© 2022 - 2024 — McMap. All rights reserved.