Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embedded list validation #1286

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
make easy solution
  • Loading branch information
SzHeJason committed Jan 10, 2017
commit ec3c185b9b0f4c318b8d8b49f88c3ae266f23bb2
23 changes: 11 additions & 12 deletions src/javascripts/ng-admin/Crud/field/maEmbeddedListField.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function maEmbeddedListField() {
scope.fields = targetFields;
scope.formName = [];
scope.targetEntity = targetEntity;

scope.entries = Entry
.createArrayFromRest(scope.value || [], targetFields, targetEntityName, targetEntity.identifier().name())
.sort((entry1, entry2) => {
Expand All @@ -46,8 +47,8 @@ export default function maEmbeddedListField() {
scope.remove = entry => {
scope.entries = scope.entries.filter(e => e !== entry);
};
scope.init = ($index) => {
scope.formName[$index] = scope.$parent.form ? scope.$parent.form['subform_' + $index] : "";
scope.getForm = function (formName) {
return scope.$parent.form[formName] || scope[formName];
}
scope.$watch('entries', (newEntries, oldEntries) => {
if (newEntries === oldEntries) {
Expand All @@ -60,16 +61,14 @@ export default function maEmbeddedListField() {
template: `
<div class="row">
<div class="col-sm-12">
<ng-form ng-repeat="entry in entries track by $index" class="subentry" name="subform_{{$index}}" >
<div ng-init="init($index)">
<div class="remove_button_container">
<a class="btn btn-default btn-sm" ng-click="remove(entry)"><span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span>&nbsp;<span translate="REMOVE"></span></a>
</div>
<div class="form-field form-group" ng-init="tmpFormName = formName[$parent.$index]" ng-repeat="field in ::fields track by $index">
<ma-field field="::field" value="entry.values[field.name()]" entry="entry" entity="::targetEntity" form="::tmpFormName" datastore="::datastore()"></ma-field>
</div>
<hr/>
<ng-form ng-repeat="entry in entries track by $index" class="subentry" name="subform_{{$index}}" ng-init="formName = 'subform_' + $index">
<div class="remove_button_container">
<a class="btn btn-default btn-sm" ng-click="remove(entry)"><span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span>&nbsp;<span translate="REMOVE"></span></a>
</div>
<div class="form-field form-group" ng-repeat="field in ::fields track by $index">
<ma-field field="::field" value="entry.values[field.name()]" entry="entry" entity="::targetEntity" form="getForm(formName)" datastore="::datastore()"></ma-field>
</div>
<hr/>
</ng-form>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
Expand All @@ -81,4 +80,4 @@ export default function maEmbeddedListField() {
};
}

maEmbeddedListField.$inject = [];
maEmbeddedListField.$inject = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing file end of line.