#707 - Fix clearempty

This commit is contained in:
Elio Struyf
2023-11-13 20:29:49 +00:00
parent 03aee57221
commit f857b0eaa8
2 changed files with 11 additions and 1 deletions
+1
View File
@@ -30,6 +30,7 @@
- [#699](https://github.com/estruyf/vscode-front-matter/issues/699): Changing border theme variable for the dashboard header
- [#703](https://github.com/estruyf/vscode-front-matter/issues/703): Fix retrieval of Astro Collections for `pnpm` projects
- [#704](https://github.com/estruyf/vscode-front-matter/issues/704): Fix `zod` schema script for optional fields
- [#707](https://github.com/estruyf/vscode-front-matter/issues/707): Fix `clearEmpty` issue with `draft` and `boolean` fields which are by default set to `true`
## [9.3.1] - 2023-10-27
+10 -1
View File
@@ -257,9 +257,18 @@ export class DataListener extends BaseListener {
}
const contentType = ArticleHelper.getContentType(article);
const sourceField = ContentType.findFieldByName(contentType.fields, field);
if (!value && field !== titleField && contentType.clearEmpty) {
value = undefined;
// Check if the draft or boolean field needs to be cleared
// This is only required when the default value is not set to true
if (sourceField && (sourceField.type === 'draft' || sourceField.type === 'boolean')) {
if (!sourceField.default) {
value = undefined;
}
} else {
value = undefined;
}
}
const dateFields = ContentType.findFieldsByTypeDeep(contentType.fields, 'datetime');