mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 08:18:43 -03:30
Merge pull request #11158 from AlexSCorey/11137-FixSurveyIntegerValidation
Properly validates Integer Survey Question with min value of 0
This commit is contained in:
@@ -72,7 +72,7 @@ function getInitialValues(launchConfig, surveyConfig, resource) {
|
|||||||
? question.default.split('\n')
|
? question.default.split('\n')
|
||||||
: [];
|
: [];
|
||||||
} else {
|
} else {
|
||||||
values[`survey_${question.variable}`] = question.default || '';
|
values[`survey_${question.variable}`] = question.default ?? '';
|
||||||
}
|
}
|
||||||
if (resource?.extra_data) {
|
if (resource?.extra_data) {
|
||||||
Object.entries(resource.extra_data).forEach(([key, value]) => {
|
Object.entries(resource.extra_data).forEach(([key, value]) => {
|
||||||
@@ -129,11 +129,14 @@ function checkForError(launchConfig, surveyConfig, values) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isNumeric && (value || value === 0)) {
|
if (isNumeric && (value || value === 0)) {
|
||||||
if (value < question.min || value > question.max) {
|
if (
|
||||||
|
(value < question.min || value > question.max) &&
|
||||||
|
question.required
|
||||||
|
) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (question.required && (!value || value.length === 0)) {
|
if (question.required && (!value || value.length === 0) && !isNumeric) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ function SurveyQuestionForm({
|
|||||||
variable: question?.variable || '',
|
variable: question?.variable || '',
|
||||||
min: question?.min || 0,
|
min: question?.min || 0,
|
||||||
max: question?.max || 1024,
|
max: question?.max || 1024,
|
||||||
default: question?.default || '',
|
default: question?.default ?? '',
|
||||||
choices: question?.choices || '',
|
choices: question?.choices || '',
|
||||||
formattedChoices: [{ choice: '', isDefault: false, id: 0 }],
|
formattedChoices: [{ choice: '', isDefault: false, id: 0 }],
|
||||||
new_question: !question,
|
new_question: !question,
|
||||||
|
|||||||
Reference in New Issue
Block a user