Skip to content

Commit 46062f6

Browse files
committed
chore: AddCommentForm: highlight as errored a form-group rather than a whole form
No functional changes.
1 parent 7ee6328 commit 46062f6

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/main/frontend/src/components/AddCommentForm.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AddCommentFormView extends React.PureComponent {
9696
<div className="col-sm-12 form-group">
9797
<form id="add-comment-form"
9898
aria-label={ l10n['t_add_comment'] || 'Add a comment' }
99-
className={ `form-horizontal ${hasValidationErrors ? 'has-error' : ''}` }
99+
className="form-horizontal"
100100
onSubmit={ handleSubmit }>
101101
{ hasServerError &&
102102
<div id="add-comment-failed-msg"
@@ -105,7 +105,7 @@ class AddCommentFormView extends React.PureComponent {
105105
{ l10n['t_server_error'] || 'Server error' }
106106
</div>
107107
}
108-
<div className="form-group form-group-sm">
108+
<div className={ `form-group form-group-sm ${hasValidationErrors ? 'has-error' : ''}` }>
109109
<label htmlFor="new-comment" className="control-label col-sm-3 required-field">
110110
{ l10n['t_comment'] || 'Comment' }
111111
</label>
@@ -118,14 +118,14 @@ class AddCommentFormView extends React.PureComponent {
118118
required="required"
119119
onChange={ handleChange }>
120120
</textarea>
121+
{ hasValidationErrors &&
122+
<span id="new-comment.errors" className="help-block">
123+
{ validationErrors.join(', ') }
124+
</span>
125+
}
121126
</div>
122127
</div>
123128
<div className="col-sm-offset-3 col-sm-9">
124-
{ hasValidationErrors &&
125-
<span id="new-comment.errors" className="help-block">
126-
{ validationErrors.join(', ') }
127-
</span>
128-
}
129129
<button
130130
type="submit"
131131
className="btn btn-primary btn-sm"

src/main/frontend/src/components/AddCommentForm.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ describe('AddCommentFormView', () => {
5050
<AddCommentFormView validationErrors={ [ 'err1', 'err2' ] } />
5151
);
5252
// then
53-
const form = screen.getByRole('form', {name: 'Add a comment'});
54-
expect(form).not.toBeNull();
55-
expect(form).toHaveClass('has-error');
56-
5753
// @todo #1489 Use toHaveErrorMessage() or toHaveDescription() for checking error messages
5854
const fieldErrors = container.querySelector('#new-comment\\.errors');
5955
expect(fieldErrors).not.toBeNull();

0 commit comments

Comments
 (0)