Skip to content

Commit

Permalink
Fix validation of tasks completion when editing a post
Browse files Browse the repository at this point in the history
Delay validation check till the post is fully rendered

Refs ushahidi/platform#1991
  • Loading branch information
rjmackay committed Aug 24, 2017
1 parent 596ea4b commit 0b9d01e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
15 changes: 10 additions & 5 deletions app/main/posts/modify/post-editor.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PostEditorController.$inject = [
'$filter',
'$location',
'$translate',
'$timeout',
'moment',
'PostEntity',
'PostEndpoint',
Expand All @@ -43,6 +44,7 @@ function PostEditorController(
$filter,
$location,
$translate,
$timeout,
moment,
postEntity,
PostEndpoint,
Expand Down Expand Up @@ -87,11 +89,14 @@ function PostEditorController(
$scope.post.form = $scope.form;
$scope.fetchAttributesAndTasks($scope.post.form.id)
.then(function () {
// If the post in marked as 'Published' but it is not in
// a valid state to be saved as 'Published' warn the user
if ($scope.post.status === 'published' && !canSavePost()) {
Notify.error('post.valid.invalid_state');
}
// Use $timeout to delay this check till after form fields are rendered.
$timeout(() => {
// If the post in marked as 'Published' but it is not in
// a valid state to be saved as 'Published' warn the user
if ($scope.post.status === 'published' && !canSavePost()) {
Notify.error('post.valid.invalid_state');
}
});
});

$scope.medias = {};
Expand Down
2 changes: 1 addition & 1 deletion app/main/posts/modify/post-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h1 class="mode-context-title">{{post.form.name}}</h1>
<!-- End post stage default fields -->

<!-- Start Post custom fields -->

<post-value-edit
ng-repeat="attribute in tasks[0].attributes | orderBy: 'priority' as filtered_result track by attribute.id"
post="post"
Expand Down
14 changes: 7 additions & 7 deletions app/main/posts/modify/post-value-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,39 +201,39 @@

<!-- type: categories -->
<div ng-switch-when="tags">
<div
<div
class="form-field checkbox"
ng-repeat="option in attribute.options"
ng-if="option.parent_id === null"
>
<label>
<input
<input
type="checkbox"
checklist-model="post.values[attribute.key]"
name="values_{{attribute.id}}_{{option}}"
name="values_{{attribute.id}}_{{option.id}}"
checklist-value="option.id"
value="option.id"
ng-click="selectParent(option, attribute.key)"
>
{{option.tag}}
</label>
<div
<div
class="form-field checkbox"
ng-if="option.children"
ng-repeat="child in option.children"
>
<label>
<input
<input
type="checkbox"
checklist-model="post.values[attribute.key]"
name="values_{{attribute.id}}_{{child}}"
name="values_{{attribute.id}}_{{child.id}}"
checklist-value="child.id"
value="child.id"
ng-click="selectChild(child, attribute.key)"
>
{{child.tag}}
</label>
</div>
</div>
</div>

<add-category
Expand Down

0 comments on commit 0b9d01e

Please sign in to comment.