Skip to content

Commit 0b9d01e

Browse files
committed
Fix validation of tasks completion when editing a post
Delay validation check till the post is fully rendered Refs ushahidi/platform#1991
1 parent 596ea4b commit 0b9d01e

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

app/main/posts/modify/post-editor.directive.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PostEditorController.$inject = [
2222
'$filter',
2323
'$location',
2424
'$translate',
25+
'$timeout',
2526
'moment',
2627
'PostEntity',
2728
'PostEndpoint',
@@ -43,6 +44,7 @@ function PostEditorController(
4344
$filter,
4445
$location,
4546
$translate,
47+
$timeout,
4648
moment,
4749
postEntity,
4850
PostEndpoint,
@@ -87,11 +89,14 @@ function PostEditorController(
8789
$scope.post.form = $scope.form;
8890
$scope.fetchAttributesAndTasks($scope.post.form.id)
8991
.then(function () {
90-
// If the post in marked as 'Published' but it is not in
91-
// a valid state to be saved as 'Published' warn the user
92-
if ($scope.post.status === 'published' && !canSavePost()) {
93-
Notify.error('post.valid.invalid_state');
94-
}
92+
// Use $timeout to delay this check till after form fields are rendered.
93+
$timeout(() => {
94+
// If the post in marked as 'Published' but it is not in
95+
// a valid state to be saved as 'Published' warn the user
96+
if ($scope.post.status === 'published' && !canSavePost()) {
97+
Notify.error('post.valid.invalid_state');
98+
}
99+
});
95100
});
96101

97102
$scope.medias = {};

app/main/posts/modify/post-editor.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ <h1 class="mode-context-title">{{post.form.name}}</h1>
107107
<!-- End post stage default fields -->
108108

109109
<!-- Start Post custom fields -->
110-
110+
111111
<post-value-edit
112112
ng-repeat="attribute in tasks[0].attributes | orderBy: 'priority' as filtered_result track by attribute.id"
113113
post="post"

app/main/posts/modify/post-value-edit.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -201,39 +201,39 @@
201201

202202
<!-- type: categories -->
203203
<div ng-switch-when="tags">
204-
<div
204+
<div
205205
class="form-field checkbox"
206206
ng-repeat="option in attribute.options"
207207
ng-if="option.parent_id === null"
208208
>
209209
<label>
210-
<input
210+
<input
211211
type="checkbox"
212212
checklist-model="post.values[attribute.key]"
213-
name="values_{{attribute.id}}_{{option}}"
213+
name="values_{{attribute.id}}_{{option.id}}"
214214
checklist-value="option.id"
215215
value="option.id"
216216
ng-click="selectParent(option, attribute.key)"
217217
>
218218
{{option.tag}}
219219
</label>
220-
<div
220+
<div
221221
class="form-field checkbox"
222222
ng-if="option.children"
223223
ng-repeat="child in option.children"
224224
>
225225
<label>
226-
<input
226+
<input
227227
type="checkbox"
228228
checklist-model="post.values[attribute.key]"
229-
name="values_{{attribute.id}}_{{child}}"
229+
name="values_{{attribute.id}}_{{child.id}}"
230230
checklist-value="child.id"
231231
value="child.id"
232232
ng-click="selectChild(child, attribute.key)"
233233
>
234234
{{child.tag}}
235235
</label>
236-
</div>
236+
</div>
237237
</div>
238238

239239
<add-category

0 commit comments

Comments
 (0)