2014-06-05 18 views
12

我想创建一个窗体,其中一个文本字段值取决于另一个文本框。角度可编辑更新本地模型问题

参考angularjs,默认情况下xeditable更新局部模型点击save.But后,我想立刻更新模型,并在另一个文本框

<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> 

我附上样品的工作显示更新的值代码jsfiddle

+0

点击保存按钮更新 –

回答

1

其更新

检查这个

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> 
+1

后NG-模型值谢谢您的答复。但我想要的是,当我在文本框1中输入值时,它应该更新包含模型的文本框2,其值取决于模型1。 – Pravin

+0

这意味着在键入自己的时候你想要在文本框中改变数据值2 –

+0

是的。当然。 @NidhishKrishnan – Pravin

3

@Pravin我认为我找到了解决办法。当用户在键入输入中选择字典条目时,我遇到需要更新可编辑模式的情况。我一直在寻找解决方案,我发现下面的方法:

<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> 

而且方法,更新xeditable数据:

$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 
     }); 

    }; 

我希望它能帮助。

UPDATE [的jsfiddle]

https://jsfiddle.net/fLc2sdd2/

+0

您能否将您的解决方案包含在小提琴中? @przemek – Pravin

+0

我已经添加了示例小提琴。您可以尝试选择状态,然后更改用户名。你可以尝试更多... –