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
try again
  • Loading branch information
SzHeJason committed Jan 10, 2017
commit f91be337581b25bd700980d2bd0ebb5b29c62ceb
26 changes: 17 additions & 9 deletions src/javascripts/ng-admin/Crud/field/maEmbeddedListField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function maEmbeddedListField() {
filterFunc = () => true;
}
scope.fields = targetFields;
scope.formName = [];
// scope.formNamex = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code, please remove.

scope.targetEntity = targetEntity;
scope.entries = Entry
.createArrayFromRest(scope.value || [], targetFields, targetEntityName, targetEntity.identifier().name())
Expand All @@ -45,6 +47,9 @@ 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] : "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Coding style: please add spaces before and after ?. :)

}
scope.$watch('entries', (newEntries, oldEntries) => {
if (newEntries === oldEntries) {
return;
Expand All @@ -55,22 +60,25 @@ 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}}" 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="formName" datastore="::datastore()"></ma-field>
<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/>
</div>
<hr/>
</ng-form>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-default btn-sm" ng-click="addNew()"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>&nbsp;<span translate="ADD_NEW" translate-values="{ name: field().label().toLowerCase() }"></span></a>
</div>
</div>
</div></div>`
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

An indentation is missing here.

</div>`
};
}

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.