Skip to content

Commit 00446a0

Browse files
committed
Accessibility and web standards compliance improvements
1 parent 64db276 commit 00446a0

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/client/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ declare module fng {
106106
placeHolder?: string // adds placeholder text to the input (depending on data type).
107107
help?: string; // adds help text under the input.
108108
helpInline?: string; // adds help to the right of the input.
109-
popup?: string; // adds popup help as specified.
109+
popup?: string; // adds title (popup help) as specified.
110+
ariaLabel?: string; // adds aria-label as specified.
110111
order?: number; // allows user to specify the order / tab order of this field in the form. This overrides the position in the Mongoose schema.
111112
size?: 'mini' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | 'block-level'; // sets control width. Default is 'medium''
112113
readonly?: boolean | string; // adds the readonly or ng-readonly attribute to the generated input (currently doesn't work with date - and perhaps other types).

src/client/js/directives/form.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ module fng.directives {
134134
} else {
135135
common += handleReadOnlyDisabled(fieldInfo.readonly);
136136
common += fieldInfo.add ? (' ' + fieldInfo.add + ' ') : '';
137+
common += ` aria-label="${fieldInfo.label && fieldInfo.label !== "" ? fieldInfo.label : fieldInfo.name}" `;
137138
value = '<select ' + common + 'class="' + allInputsVars.formControl.trim() + allInputsVars.compactClass + allInputsVars.sizeClassBS2 + '" ' + requiredStr + '>';
138139

139140
if (!isRequired) {
@@ -210,10 +211,9 @@ module fng.directives {
210211
case 'checkbox' :
211212
common += requiredStr;
212213
common += handleReadOnlyDisabled(fieldInfo.readonly);
214+
value = formMarkupHelper.generateSimpleInput(common, fieldInfo, options);
213215
if (cssFrameworkService.framework() === 'bs3') {
214-
value = '<div class="checkbox"><input ' + common + 'type="checkbox"></div>';
215-
} else {
216-
value = formMarkupHelper.generateSimpleInput(common, fieldInfo, options);
216+
value = '<div class="checkbox">' + value + '</div>';
217217
}
218218
break;
219219
default:

src/client/js/services/form-markup-helper.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module fng.services {
44

55
/*@ngInject*/
6-
export function formMarkupHelper(cssFrameworkService, inputSizeHelper, addAllService) {
6+
export function formMarkupHelper(cssFrameworkService, inputSizeHelper, addAllService, $filter) {
77

88
function generateNgShow(showWhen, model) {
99

@@ -165,11 +165,14 @@ module fng.services {
165165
if (['inline','stacked'].includes(options.formstyle)) {
166166
placeHolder = placeHolder || fieldInfo.label;
167167
}
168-
common = 'ng-model="' + modelString + '"' + (idString ? ' id="' + idString + '" name="' + idString + '" ' : ' name="' + nameString + '" ');
168+
common = 'data-ng-model="' + modelString + '"' + (idString ? ' id="' + idString + '" name="' + idString + '" ' : ' name="' + nameString + '" ');
169169
common += (placeHolder ? ('placeholder="' + placeHolder + '" ') : '');
170170
if (fieldInfo.popup) {
171171
common += 'title="' + fieldInfo.popup + '" ';
172172
}
173+
if (fieldInfo.ariaLabel) {
174+
common += 'aria-label="' + fieldInfo.ariaLabel + '" ';
175+
}
173176
common += addAllService.addAll(scope, 'Field', null, options);
174177
return {
175178
common: common,
@@ -206,8 +209,10 @@ module fng.services {
206209

207210
generateSimpleInput: function generateSimpleInput(common, fieldInfo, options) {
208211
var result = '<input ' + common + 'type="' + fieldInfo.type + '" ';
209-
if (!fieldInfo.label) {
210-
result += `placeholder="${fieldInfo.name.replace(/\./g,' ')}" `
212+
if (!fieldInfo.label && !fieldInfo.ariaLabel) {
213+
result += `aria-label="${fieldInfo.name.replace(/\./g,' ')}" `
214+
} else if (options.subschema) {
215+
result += `aria-label="${fieldInfo.label ? ($filter('titleCase')(options.subschemaroot) + ' ' + fieldInfo.label) : (fieldInfo.popup || fieldInfo.name.replace(/\./g,' '))}" `
211216
}
212217
if (options.formstyle === 'inline' && cssFrameworkService.framework() === 'bs2' && !fieldInfo.size) {
213218
result += 'class="input-small"';

src/client/template/base-edit.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<error-display></error-display>
33
<div ng-class="css('rowFluid')" class="page-header edit-header">
44
<div class="header-lhs col-sm-8 span8">
5-
<h4 id="header-text">{{modelNameDisplay}} :
5+
<h1 id="header-text">{{modelNameDisplay}} :
66
<span id="header-data-desc">
77
<span ng-show="!!editFormHeader" >{{ editFormHeader() }}</span>
88
<span ng-hide="!!editFormHeader" ng-repeat="field in listSchema" ng-bind-html="getListData(record, field.name) + ' '"></span>
99
</span>
10-
</h4>
10+
</h1>
1111
</div>
1212
<div class="header-rhs col-sm-2 span2">
1313
<div form-buttons></div>

src/client/template/base-view.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<error-display></error-display>
33
<div ng-class="css('rowFluid')" class="page-header edit-header">
44
<div class="header-lhs col-sm-8 span8">
5-
<h4>{{modelNameDisplay}} :
5+
<h1 id="header-text">{{modelNameDisplay}} :
66
<span ng-repeat="field in listSchema" ng-bind-html="getListData(record, field.name) + ' '"></span>
7-
</h4>
7+
</h1>
88
</div>
99
</div>
1010
<div class="container-fluid page-body edit-body">

test/unit/formInputSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ describe('formInput', function () {
742742
input = angular.element(elm.find('input')[11]);
743743

744744
expect(input.attr('name')).toBe('1-exams-result');
745-
expect(input.attr('ng-model')).toBe('record.exams[$parent.$index].result');
745+
expect(input.attr('data-ng-model')).toBe('record.exams[$parent.$index].result');
746746
});
747747

748748
});
@@ -898,9 +898,9 @@ describe('formInput', function () {
898898

899899
it('should put the index in the correct place in the ng-model attribute', function () {
900900
var input = angular.element(elm.find('input')[1]);
901-
expect(input.attr('ng-model')).toBe('record.mentions[$index].someString');
901+
expect(input.attr('data-ng-model')).toBe('record.mentions[$index].someString');
902902
input = angular.element(elm.find('input')[2]);
903-
expect(input.attr('ng-model')).toBe('record.mentions[$index].grades.low');
903+
expect(input.attr('data-ng-model')).toBe('record.mentions[$index].grades.low');
904904
});
905905

906906
});

0 commit comments

Comments
 (0)