Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fields validation to include field presets #10882

Merged
merged 1 commit into from
Feb 4, 2022
Merged

Conversation

azrikahar
Copy link
Contributor

@azrikahar azrikahar commented Jan 6, 2022

Fixes #10854

Bug

Field presets are not taken into account during validation. Even though the field is already filled by preset, the form returns value is required:
9KCgxosx8o

Investigation

During the validation process, fields.value are checked with conditions and if default value isNil:

const fieldsWithConditions = fields.value.map((field) => applyConditions(item, field));
const requiredFields = fieldsWithConditions.filter((field) => field.meta?.required === true);
for (const field of requiredFields) {
if (isNew.value === true && isNil(field.schema?.default_value)) {
validationRules._and.push({
[field.field]: {
_submitted: true,
},
});
}

However fields.value came from useCollection:

const { info: collectionInfo, primaryKeyField, fields } = useCollection(collection);

Which does not have field presets merged as default values. Fields with presets are returned from usePermission instead:

if (permissions.presets) {
fields = fields.map((field: Field) => {
if (field.field in permissions.presets!) {
field.schema = {
...(field.schema || {}),
default_value: permissions.presets![field.field],
} as any;
}
return field;
});
}
return fields;
});

Solution

JKMWtt5YgC


This PR requires #10782 to be fixed first, due to the presets wrongly parsed as filter syntax. That causes it to be interpreted as creating a new relational item instead:

g9iume8LXE

@krwrang
Copy link

krwrang commented Feb 4, 2022

I hope you can get this one out now since #10782 was closed and released. This has blocked our progress for long enough.

@azrikahar azrikahar marked this pull request as ready for review February 4, 2022 07:26
@azrikahar azrikahar added this to the v9-next milestone Feb 4, 2022
@rijkvanzanten rijkvanzanten self-assigned this Feb 4, 2022
@rijkvanzanten rijkvanzanten merged commit d7e45f4 into main Feb 4, 2022
@rijkvanzanten rijkvanzanten deleted the issue/10854 branch February 4, 2022 13:44
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Role permission field preset filled item not valid
3 participants