admin管理员组文章数量:1332896
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
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
Share Improve this question edited Jun 5, 2014 at 7:37 Pravin asked Jun 5, 2014 at 7:24 PravinPravin 6453 gold badges7 silver badges21 bronze badges 1- ng-model value after clicking the save button is updating – Nidhish Krishnan Commented Jun 5, 2014 at 7:37
2 Answers
Reset to default 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/fLc2sdd2/
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>
本文标签: javascriptIssue in updating local model in angular xeditableStack Overflow
版权声明:本文标题:javascript - Issue in updating local model in angular xeditable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315551a2451746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论