Skip to content

Commit

Permalink
Fix empty field array bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbo committed Nov 13, 2024
1 parent 20c24c6 commit 94d3aab
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1278,10 +1278,10 @@
person.facts = [];
person.fields = [];
if (age && age.length > 0) {
person.fields.push(makeAgeField(age));
addField(person, makeAgeField(age));
}
if (role) {
person.fields.push(makeRoleField(role));
addField(person, makeRoleField(role));
}

let name = {};
Expand Down Expand Up @@ -1987,6 +1987,13 @@
};
}

function addField(fieldHolder, field) {
if (!fieldHolder.fields) {
fieldHolder.fields = [];
}
fieldHolder.fields.push(field);
}

function addPersonFact() {
let doc = editor.get();

Expand All @@ -2005,17 +2012,12 @@
let age = $("#new-person-fact-age").val();
if (factType.endsWith("/Age")) {
if (age) {
let field = makeAgeField(age)

if (!person.fields) {
person.fields = [];
}
person.fields.push(field);
addField(person, makeAgeField(age));
}
} else if (factType === GX_ROLE) {
const role = $("#new-person-fact-role").val();
if (role) {
person.fields.push(makeRoleField(role));
addField(person, makeRoleField(role));
}
} else {
let fact = {};
Expand Down Expand Up @@ -2116,7 +2118,7 @@

const role = $("#new-person-fact-role2").val();
if (role) {
person.fields.push(makeRoleField(role));
addField(person, makeRoleField(role));
}

const fact = {
Expand Down Expand Up @@ -2184,10 +2186,7 @@
if (fact) {
// We had a fact, but turned it into an age. So delete that fact before adding a new age.
person.facts = person.facts.filter(function(fact) {return fact.id !== fid});
if (!person.fields) {
person.fields = [];
}
person.fields.push(ageField);
addField(person, ageField);
}
else if (age) {
// The Age field is being edited, so update it
Expand Down

0 comments on commit 94d3aab

Please sign in to comment.