Skip to content

Commit ff60396

Browse files
feat(field): allow displaying error message without user interaction
ref: DTRSD-123286 Signed-off-by: Jacques Larique <[email protected]>
1 parent bcb0321 commit ff60396

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

packages/components/field/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ angular.module('myModule', ['oui.field'])
3131

3232
## Component `oui-field`
3333

34-
| Attribute | Type | Binding | One-time binding | Values | Default | Description
35-
| ---- | ---- | ---- | ---- | ---- | ---- | ----
36-
| `label` | string | @? | no | n/a | n/a | field label
37-
| `label-popover` | string | @? | no | n/a | n/a | text to describe the field or give more information
38-
| `help-text` | string | @? | no | n/a | n/a | text to help fill the form field
39-
| `size` | string | @? | yes | `xs`, `s`, `m`, `l`, `xl`, `auto` | `auto` | field size
40-
| `error-messages` | object | <? | no | n/a | n/a | dictionary to override default messages
34+
| Attribute | Type | Binding | One-time binding | Values | Default | Description
35+
|-----------------------|---------| ---- | ---- |-----------------------------------| ---- | ----
36+
| `label` | string | @? | no | n/a | n/a | field label
37+
| `label-popover` | string | @? | no | n/a | n/a | text to describe the field or give more information
38+
| `help-text` | string | @? | no | n/a | n/a | text to help fill the form field
39+
| `size` | string | @? | yes | `xs`, `s`, `m`, `l`, `xl`, `auto` | `auto` | field size
40+
| `force-error-display` | boolean | <? | no | true / false | n/a | allow to display error messages even if the field is not blurred nor form submitted
41+
| `error-messages` | object | <? | no | n/a | n/a | dictionary to override default messages

packages/components/field/src/js/field.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
size: '@?',
99
errorMessages: '<?',
1010
labelPopover: '@?',
11+
forceErrorDisplay: '<?',
1112
},
1213
controller,
1314
require: {

packages/components/field/src/js/field.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export default class FieldController {
148148
}
149149

150150
this.checkAllErrors();
151-
return this.invalid && (this.blurred || this.form.$submitted);
151+
return this.invalid && (this.forceErrorDisplay || this.blurred || this.form.$submitted);
152152
}
153153

154154
checkAllErrors() {

packages/components/field/src/js/field.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,29 @@ describe('ouiField', () => {
739739
$timeout.flush();
740740
expect(element[0].querySelector('.oui-field__error')).not.toBeNull();
741741
});
742+
743+
it('should show error without user interaction', () => {
744+
const element = TestUtils.compileTemplate(`
745+
<form name="form" ng-submit="$ctrl.noop()">
746+
<oui-field label="{{'username'}}" force-error-display="true">
747+
<input type="text"
748+
class="oui-input"
749+
type="text"
750+
id="username"
751+
name="username"
752+
required
753+
ng-model="$ctrl.username">
754+
</oui-field>
755+
<button type="submit">Ok</button>
756+
</form>
757+
`, {
758+
noop,
759+
});
760+
$timeout.flush();
761+
762+
// Initial state
763+
expect(element[0].querySelector('.oui-field__error')).not.toBeNull();
764+
});
742765
});
743766
});
744767
});

0 commit comments

Comments
 (0)