Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 1a63dc8

Browse files
author
Nick Litwin
committed
Add validation and error messages for fonts section
1 parent d850588 commit 1a63dc8

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

app/directives/tc-form-fonts/tc-form-fonts.directive.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
function tcFormFonts() {
77
return {
88
restrict: 'E',
9+
require: '^form',
910
templateUrl: 'directives/tc-form-fonts/tc-form-fonts.html',
1011
scope: {
1112
formFonts: '='
1213
},
13-
link: function(scope, element, attrs) {
14-
// console.log('scope on font submission directive: ', scope.submissionForm);
15-
14+
link: function(scope, element, attrs, formController) {
15+
scope.submissionForm = formController;
1616
},
1717
controller: ['$scope', function($scope) {
1818
// Must provide React Select component a list with ID, since currently
@@ -35,6 +35,20 @@
3535
// Find the right font section and change that source value to the value that the user selected
3636
var id = newFont.id;
3737
$scope.formFonts[id].source = newFont.value;
38+
39+
if (newFont.value === 'STUDIO_STANDARD_FONTS_LIST') {
40+
$scope.formFonts[id].isFontNameRequired = true;
41+
$scope.formFonts[id].isFontNameDisabled = false;
42+
$scope.formFonts[id].isFontUrlRequired = false;
43+
$scope.formFonts[id].isFontUrlDisabled = false;
44+
45+
} else if (newFont.value) {
46+
$scope.formFonts[id].isFontNameRequired = true;
47+
$scope.formFonts[id].isFontNameDisabled = false;
48+
$scope.formFonts[id].isFontUrlRequired = true;
49+
$scope.formFonts[id].isFontUrlDisabled = false;
50+
51+
}
3852
};
3953

4054
$scope.createAdditionalFontFieldset = function() {
@@ -51,7 +65,12 @@
5165
id: newId,
5266
source: '',
5367
name: '',
54-
sourceUrl: ''
68+
sourceUrl: '',
69+
isFontUrlRequired: false,
70+
isFontUrlDisabled: true,
71+
isFontNameRequired: false,
72+
isFontNameDisabled: true,
73+
isFontSourceRequired: false
5574
});
5675
}
5776
}]

app/directives/tc-form-fonts/tc-form-fonts.jade

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
dropdown(
55
name="'font-source{{$index}}'",
66
options="fontList{{$index}}",
7-
placeholder="'Select from the list'",
7+
placeholder="'Select a provider from the list'",
88
searchable="false",
99
clearable="false",
1010
on-change="selectFont",
@@ -15,14 +15,32 @@
1515
label-text="Font Name",
1616
placeholder="Select font source to edit field"
1717
input-value="font.name",
18-
input-name="fontName{{$index}}"
18+
input-name="fontName{{$index}}",
19+
input-required="formFonts[$index].isFontNameRequired",
20+
input-disabled="formFonts[$index].isFontNameDisabled"
1921
)
2022

23+
.tc-error-messages(
24+
ng-show="submissionForm['fontName' + $index].$dirty && submissionForm['fontName' + $index].$invalid"
25+
ng-messages="submissionForm['fontName' + $index].$error"
26+
)
27+
p(ng-message="required") This field is required.
28+
2129
tc-input.fieldset__input(
2230
label-text="Font URL",
2331
placeholder="Select font source to edit field",
2432
input-value="font.sourceUrl",
25-
input-name="fontUrl{{$index}}"
33+
input-name="fontUrl{{$index}}",
34+
input-required="formFonts[$index].isFontUrlRequired",
35+
input-disabled="formFonts[$index].isFontUrlDisabled",
36+
input-pattern="urlRegEx"
37+
)
38+
39+
.tc-error-messages(
40+
ng-show="submissionForm['fontUrl' + $index].$dirty && submissionForm['fontUrl' + $index].$invalid"
41+
ng-messages="submissionForm['fontUrl' + $index].$error"
2642
)
43+
p(ng-message="pattern") Please enter a valid url.
44+
p(ng-message="required") This field is required.
2745

2846
button.fieldset__button.tc-btn.tc-btn-s(type="button", ng-click="createAdditionalFontFieldset()") + Add Font

app/submissions/submit-file/submit-file.controller.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
vm.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
1212
vm.rankRegEx = new RegExp(/^[1-9]\d*$/);
1313
vm.comments = '';
14-
15-
// New formFonts prop
1614
vm.formFonts = [{
1715
id: 0,
1816
source: '',
1917
name: '',
20-
sourceUrl: ''
18+
sourceUrl: '',
19+
isFontUrlRequired: false,
20+
isFontUrlDisabled: true,
21+
isFontNameRequired: false,
22+
isFontNameDisabled: true,
23+
isFontSourceRequired: false
2124
}];
22-
2325
vm.submissionForm = {
2426
files: [],
2527

@@ -129,6 +131,7 @@
129131
vm.submissionsBody.data.submitterComments = vm.comments;
130132
vm.submissionsBody.data.submitterRank = vm.submissionForm.submitterRank;
131133

134+
// Process stock art
132135
if (vm.submissionForm.stockArts[0].description === '') {
133136
vm.submissionsBody.data.stockArts = [];
134137
} else {
@@ -139,20 +142,25 @@
139142
});
140143
}
141144

142-
if (vm.submissionForm.fonts[0].source === '') {
145+
// Process fonts
146+
if (vm.formFonts[0].source === '') {
143147
vm.submissionsBody.data.fonts = [];
144148
} else {
145-
var fonts = angular.copy(vm.submissionForm.fonts);
149+
var fonts = angular.copy(vm.formFonts);
146150
vm.submissionsBody.data.fonts = fonts.map(function(font) {
147151
if (font.source) {
148152
delete font.id;
153+
delete font.isFontUrlRequired;
154+
delete font.isFontUrlDisabled;
155+
delete font.isFontNameRequired;
156+
delete font.isFontNameDisabled;
157+
delete font.isFontSourceRequired;
149158
return font;
150159
}
151160
});
152161
}
153162

154163
console.log('ABOUT TO SEND: ', vm.submissionsBody);
155-
return;
156164
SubmissionsService.getPresignedURL(vm.submissionsBody, files);
157165
}
158166
}

0 commit comments

Comments
 (0)