Skip to content

Commit 15171c8

Browse files
Apply suggestions from code review
Co-authored-by: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com>
1 parent 0674d3d commit 15171c8

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

js/modules/Forms/RendererController.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,29 @@ export class GlpiFormRendererController
158158
Object.values(response.errors).forEach(error => {
159159
// Highlight the field with error
160160
const question = $(`[data-glpi-form-renderer-id="${error.question_id}"][data-glpi-form-renderer-question]`);
161-
if (question.length) {
162-
// Find the input field within the question
163-
const inputField = question.find('input:not([data-uploader-name]), select, textarea');
164-
if (inputField.length) {
165-
// Generate a unique ID for the error message
166-
const errorId = `error-${error.question_id}`;
167-
168-
// Add validation classes and accessibility attributes
169-
inputField
170-
.addClass('is-invalid')
171-
.attr('aria-invalid', 'true')
172-
.attr('aria-errormessage', errorId);
173-
174-
// Add a tooltip with the error message
175-
inputField.parent().append(
176-
`<span id="${errorId}" class="invalid-tooltip">${error.message}</span>`
177-
);
178-
}
161+
if (!question.length) {
162+
return;
179163
}
164+
165+
// Find the input field within the question
166+
const inputField = question.find('input:not([data-uploader-name]), select, textarea');
167+
if (!inputField.length) {
168+
return;
169+
}
170+
171+
// Generate a unique ID for the error message
172+
const errorId = `error-${error.question_id}`;
173+
174+
// Add validation classes and accessibility attributes
175+
inputField
176+
.addClass('is-invalid')
177+
.attr('aria-invalid', 'true')
178+
.attr('aria-errormessage', errorId);
179+
180+
// Add a tooltip with the error message
181+
inputField.parent().append(
182+
`<span id="${errorId}" class="invalid-tooltip">${error.message}</span>`
183+
);
180184
});
181185

182186
return false;

src/Glpi/Form/ValidationResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/**
3838
* Class for handling form validation results
3939
*/
40-
class ValidationResult
40+
final class ValidationResult
4141
{
4242
/**
4343
* @var bool Indicates if the validation is successful

0 commit comments

Comments
 (0)