Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 53d546f

Browse files
Switched to using ng-form so that validation gets run, and formSubmitting event gets fired
1 parent 11e2b00 commit 53d546f

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
130130
[
131131
"$scope",
132132
"$interpolate",
133+
"formHelper",
133134
"contentResource",
134135
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
135136

136-
function ($scope, $interpolate, contentResource, dtgeResources) {
137+
function ($scope, $interpolate, formHelper, contentResource, dtgeResources) {
137138

138139
$scope.dialogOptions = $scope.$parent.dialogOptions;
139140

@@ -154,42 +155,40 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
154155

155156
$scope.save = function () {
156157

157-
// Make sure form is valid
158-
if (!$scope.dtgeForm.$valid)
159-
return;
158+
// Cause form submitting
159+
if (formHelper.submitForm({ scope: $scope, formCtrl: $scope.dtgeForm })) {
160160

161-
// Cause formSubmitting to fire
162-
$scope.$broadcast("formSubmitting", { scope: $scope });
161+
// Copy property values to scope model value
162+
if ($scope.node) {
163+
var value = {
164+
name: $scope.dialogOptions.editorName
165+
};
163166

164-
// Copy property values to scope model value
165-
if ($scope.node) {
166-
var value = {
167-
name: $scope.dialogOptions.editorName
168-
};
169-
170-
for (var t = 0; t < $scope.node.tabs.length; t++) {
171-
var tab = $scope.node.tabs[t];
172-
for (var p = 0; p < tab.properties.length; p++) {
173-
var prop = tab.properties[p];
174-
if (typeof prop.value !== "function") {
175-
value[prop.alias] = prop.value;
167+
for (var t = 0; t < $scope.node.tabs.length; t++) {
168+
var tab = $scope.node.tabs[t];
169+
for (var p = 0; p < tab.properties.length; p++) {
170+
var prop = tab.properties[p];
171+
if (typeof prop.value !== "function") {
172+
value[prop.alias] = prop.value;
173+
}
176174
}
177175
}
178-
}
179176

180-
if (nameExp) {
181-
var newName = nameExp(value); // Run it against the stored dictionary value, NOT the node object
182-
if (newName && (newName = $.trim(newName))) {
183-
value.name = newName;
177+
if (nameExp) {
178+
var newName = nameExp(value); // Run it against the stored dictionary value, NOT the node object
179+
if (newName && (newName = $.trim(newName))) {
180+
value.name = newName;
181+
}
184182
}
183+
184+
$scope.dialogData.value = value;
185+
} else {
186+
$scope.dialogData.value = null;
185187
}
186188

187-
$scope.dialogData.value = value;
188-
} else {
189-
$scope.dialogData.value = null;
190-
}
189+
$scope.submit($scope.dialogData);
191190

192-
$scope.submit($scope.dialogData);
191+
}
193192
};
194193

195194
function loadNode() {
Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
<form name="dtgeForm" novalidate class="dtge-dialog umb-panel" ng-controller="Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog">
2-
3-
<div class="umb-panel-body no-header with-footer umb-scrollable" ng-switch="dialogMode">
4-
5-
<umb-control-group label="Choose a content type" ng-switch-when="selectDocType">
6-
<select class="umb-editor" ng-change="selectDocType()" name="selectDocType" ng-model="$parent.$parent.selectedDocType" ng-options="dt as dt.name for dt in docTypes" required>
7-
<option value=""><localize key="choose" />...</option>
8-
</select>
9-
</umb-control-group>
10-
11-
<div ng-switch-when="edit">
12-
13-
<fieldset ng-repeat="tab in node.tabs">
14-
<legend style="font-size: 18px;">{{tab.alias}}</legend>
15-
16-
<umb-property
17-
property="property"
18-
ng-repeat="property in tab.properties">
19-
<umb-editor model="property"></umb-editor>
20-
</umb-property>
21-
22-
</fieldset>
1+
<ng-form name="dtgeForm">
2+
<div class="dtge-dialog umb-panel" ng-controller="Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog">
3+
4+
<div class="umb-panel-body no-header with-footer umb-scrollable" ng-switch="dialogMode">
5+
6+
<umb-control-group label="Choose a content type" ng-switch-when="selectDocType">
7+
<select class="umb-editor" ng-change="selectDocType()" name="selectDocType" ng-model="$parent.$parent.selectedDocType" ng-options="dt as dt.name for dt in docTypes" required>
8+
<option value=""><localize key="choose" />...</option>
9+
</select>
10+
</umb-control-group>
11+
12+
<div ng-switch-when="edit">
13+
14+
<fieldset ng-repeat="tab in node.tabs">
15+
<legend style="font-size: 18px;">{{tab.alias}}</legend>
16+
17+
<umb-property property="property"
18+
ng-repeat="property in tab.properties">
19+
<umb-editor model="property"></umb-editor>
20+
</umb-property>
21+
22+
</fieldset>
23+
24+
</div>
2325

2426
</div>
2527

26-
</div>
28+
<div class="umb-panel-footer">
29+
<div class="umb-el-wrap umb-panel-buttons">
30+
<div class="btn-toolbar umb-btn-toolbar">
2731

28-
<div class="umb-panel-footer">
29-
<div class="umb-el-wrap umb-panel-buttons">
30-
<div class="btn-toolbar umb-btn-toolbar">
31-
32-
<a href ng-click="close()" class="btn btn-link">
33-
<localize key="general_cancel">Cancel</localize>
34-
</a>
32+
<a href ng-click="close()" class="btn btn-link">
33+
<localize key="general_cancel">Cancel</localize>
34+
</a>
3535

36-
<button class="btn btn-primary" ng-click="save()">
37-
<localize key="buttons_save">Save</localize>
38-
</button>
36+
<button class="btn btn-primary" ng-click="save()">
37+
<localize key="buttons_save">Save</localize>
38+
</button>
3939

40+
</div>
4041
</div>
4142
</div>
4243
</div>
43-
</form>
44+
</ng-form>

0 commit comments

Comments
 (0)