mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 19:51:08 -03:30
fix form validation for Organization select in Inventory form
This commit is contained in:
@@ -77,6 +77,8 @@ function InventoryForm({
|
|||||||
form.setFieldValue('organization', value);
|
form.setFieldValue('organization', value);
|
||||||
}}
|
}}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
|
touched={form.touched.organization}
|
||||||
|
error={form.errors.organization}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
|
||||||
export function required(message, i18n) {
|
export function required(message, i18n) {
|
||||||
|
const errorMessage = message || i18n._(t`This field must not be blank`);
|
||||||
return value => {
|
return value => {
|
||||||
if (typeof value === 'string' && !value.trim()) {
|
if (typeof value === 'string' && !value.trim()) {
|
||||||
return message || i18n._(t`This field must not be blank`);
|
return errorMessage;
|
||||||
|
}
|
||||||
|
if (typeof value === 'number' && !Number.isNaN(value)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!value) {
|
||||||
|
return errorMessage;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ describe('validators', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('required interprets undefined as empty value', () => {
|
||||||
|
expect(required(null, i18n)(undefined)).toEqual({
|
||||||
|
id: 'This field must not be blank',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('required interprets 0 as non-empty value', () => {
|
||||||
|
expect(required(null, i18n)(0)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
test('maxLength accepts value below max', () => {
|
test('maxLength accepts value below max', () => {
|
||||||
expect(maxLength(10, i18n)('snazzy')).toBeUndefined();
|
expect(maxLength(10, i18n)('snazzy')).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user