Skip to content

Commit e5a69de

Browse files
committed
improve validation on UI
1 parent 72329a6 commit e5a69de

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/Darryldecode/Backend/Public/backend/cb/app/contents/controller.contents.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ angular.module('cb.group').controller('ContentsController', ['$scope','$timeout'
6969
// saves new content
7070
$scope.content.save = function () {
7171

72+
var validation = checkRequiredFields();
73+
74+
if( ! validation.success ) {
75+
AlertService.showAlert(validation.message);
76+
return false;
77+
}
78+
7279
var dataToBeSave = {
7380
title: $scope.content.title,
7481
slug: $scope.content.slug,
@@ -114,6 +121,13 @@ angular.module('cb.group').controller('ContentsController', ['$scope','$timeout'
114121
// update content
115122
$scope.content.updateSave = function () {
116123

124+
var validation = checkRequiredFields();
125+
126+
if( ! validation.success ) {
127+
AlertService.showAlert(validation.message);
128+
return false;
129+
}
130+
117131
var dataToBeUpdated = {
118132
title: $scope.content.title,
119133
slug: $scope.content.slug,
@@ -459,4 +473,33 @@ angular.module('cb.group').controller('ContentsController', ['$scope','$timeout'
459473
});
460474
return taxString;
461475
}
476+
477+
// this will check all custom fields that are required
478+
function checkRequiredFields() {
479+
480+
var result = {
481+
success: true,
482+
message: ''
483+
};
484+
485+
angular.forEach($scope.contentType.form_groups, function(group, i) {
486+
angular.forEach(group.fields, function(field, i) {
487+
if( field.data.required == true ) {
488+
489+
if( ! $scope.content.customFields.hasOwnProperty(group.form_name) ) {
490+
result.success = false;
491+
result.message = field.data.label + ' is required!';
492+
return;
493+
}
494+
495+
if( (!$scope.content.customFields[group.form_name].hasOwnProperty(field.data.name)) || ($scope.content.customFields[group.form_name][field.data.name].length == 0) ) {
496+
result.success = false;
497+
result.message = field.data.label + ' is required!';
498+
}
499+
}
500+
});
501+
});
502+
503+
return result;
504+
}
462505
}]);

src/Darryldecode/Backend/Public/backend/cb/app/custom-fields/fields/display/gallery.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ <h4>{{f.data.label}} {{(f.data.required) ? '*' : ''}}</h4>
2424
<!-- edit mode -->
2525
<div class="edit-field edit-field-{{f.key}}-{{$index}}">
2626
<div class="form-group text-left">
27-
<label>Field Name:</label>
28-
<textarea class="form-control" data-ng-model="f.data.label"></textarea>
27+
<label>Field Key:</label>
28+
<textarea class="form-control" data-ng-model="f.data.name"></textarea>
2929
</div>
3030
<div class="form-group text-left">
3131
<label>Label:</label>
@@ -35,5 +35,9 @@ <h4>{{f.data.label}} {{(f.data.required) ? '*' : ''}}</h4>
3535
<label>Description:</label>
3636
<textarea class="form-control" data-ng-model="f.data.description"></textarea>
3737
</div>
38+
<div class="form-group text-left">
39+
<td>Required?</td>
40+
<td><input data-ng-model="f.data.required" type="checkbox"></td>
41+
</div>
3842
</div>
3943
</div>

src/Darryldecode/Backend/Public/backend/cb/app/custom-fields/fields/display/image.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h4>{{f.data.label}} {{(f.data.required) ? '*' : ''}}</h4>
2323
<!-- edit mode -->
2424
<div class="edit-field edit-field-{{f.key}}-{{$index}}">
2525
<div class="form-group text-left">
26-
<label>Field Name:</label>
26+
<label>Field Key:</label>
2727
<textarea class="form-control" data-ng-model="f.data.name"></textarea>
2828
</div>
2929
<div class="form-group text-left">
@@ -34,5 +34,9 @@ <h4>{{f.data.label}} {{(f.data.required) ? '*' : ''}}</h4>
3434
<label>Description:</label>
3535
<textarea class="form-control" data-ng-model="f.data.description"></textarea>
3636
</div>
37+
<div class="form-group text-left">
38+
<td>Required?</td>
39+
<td><input data-ng-model="f.data.required" type="checkbox"></td>
40+
</div>
3741
</div>
3842
</div>

0 commit comments

Comments
 (0)