fix: checks

This commit is contained in:
Alexandre Bodin 2024-09-18 10:50:55 +02:00
parent 0faf896735
commit b5354baf37
5 changed files with 28 additions and 14 deletions

View File

@ -34,13 +34,7 @@
"pluginOptions": {}
},
"priceRange": {
"enum": [
"very_cheap",
"cheap",
"average",
"expensive",
"very_expensive"
],
"enum": ["very_cheap", "cheap", "average", "expensive", "very_expensive"],
"type": "enumeration",
"pluginOptions": {
"i18n": {

View File

@ -345,7 +345,13 @@ const Form = React.forwardRef<HTMLFormElement, FormProps>(
.filter((el) => el.selected)
.map((el) => el.value);
} else {
val = value;
// NOTE: reset value to null so it failes required checks.
// The API only considers a required field invalid if the value is null|undefined, to differentiate from min 1
if (value === '') {
val = null;
} else {
val = value;
}
}
if (field) {

View File

@ -77,6 +77,14 @@ describe('useDocument', () => {
id: 1,
postal_code: 'N2',
notrepeat_req: {},
repeat_req_min: [
{
name: 'toto',
},
{
name: 'toto',
},
],
city: 'London',
repeat_req: [
{
@ -98,6 +106,14 @@ describe('useDocument', () => {
name: 'toto',
},
],
repeat_req_min: [
{
name: 'toto',
},
{
name: 'toto',
},
],
})
).toMatchInlineSnapshot(`
{

View File

@ -261,11 +261,7 @@ type ValidationFn = (
options: ValidationOptions
) => <TSchema extends AnySchema>(schema: TSchema) => TSchema;
const addNullableValidation: ValidationFn = (attribute) => (schema) => {
if (attribute.required) {
return schema;
}
const addNullableValidation: ValidationFn = () => (schema) => {
return nullableSchema(schema);
};

View File

@ -224,7 +224,9 @@ const createDzValidator =
updatedAttribute,
});
validator = addMinMax(validator, { attr, updatedAttribute });
if (!isDraft) {
validator = addMinMax(validator, { attr, updatedAttribute });
}
return validator;
};