#394: Ordering of snippet fields is based on their field definition

This commit is contained in:
Elio Struyf
2022-09-05 10:37:30 +02:00
parent 69e0dc3343
commit 88c8cc82c8
2 changed files with 12 additions and 5 deletions
@@ -79,15 +79,21 @@ const SnippetForm: React.ForwardRefRenderFunction<SnippetFormHandle, ISnippetFor
const allFields: SnippetField[] = [];
const snippetFields = snippet.fields || [];
for (const fieldName of placeholders) {
const field = snippetFields.find(f => f.name === fieldName);
if (field) {
// Loop over all fields to check if they are present in the snippet
for (const field of snippetFields) {
const idx = placeholders.findIndex(fieldName => fieldName === field.name);
if (idx > -1) {
allFields.push({
...field,
value: insertPlaceholderValues(field.default || "")
});
} else {
}
}
// Loop over all placeholders to find the ones that are not present in the snippet fields
for (const fieldName of placeholders) {
const idx = snippetFields.findIndex(field => field.name === fieldName);
if (idx === -1) {
allFields.push({
name: fieldName,
title: fieldName,