3: Fix issue with adding and removing attributes

- Applied patch by @imposeren to handle bug with removing and adding
  attributes. This patch resolves the issue by refactoring the attribute
  creation logic to use loop to choose a safer default attribute key
  before creation.
This commit is contained in:
Matt Smith 2020-08-09 21:03:17 -05:00
parent 3e2a95f5f1
commit d0ec294164
2 changed files with 16 additions and 4 deletions

View file

@ -82,9 +82,15 @@ export class SimpleActorSheet extends ActorSheet {
// Add new attribute
if ( action === "create" ) {
const nk = Object.keys(attrs).length + 1;
const objKeys = Object.keys(attrs);
let nk = Object.keys(attrs).length + 1;
let newValue = `attr${nk}`;
let newKey = document.createElement("div");
newKey.innerHTML = `<input type="text" name="data.attributes.attr${nk}.key" value="attr${nk}"/>`;
while ( objKeys.includes(newValue) ) {
++nk;
newValue = `attr${nk}`;
};
newKey.innerHTML = `<input type="text" name="data.attributes.attr${nk}.key" value="${newValue}"/>`;
newKey = newKey.children[0];
form.appendChild(newKey);
await this._onSubmit(event);

View file

@ -67,9 +67,15 @@ export class SimpleItemSheet extends ItemSheet {
// Add new attribute
if ( action === "create" ) {
const nk = Object.keys(attrs).length + 1;
const objKeys = Object.keys(attrs);
let nk = Object.keys(attrs).length + 1;
let newValue = `attr${nk}`;
let newKey = document.createElement("div");
newKey.innerHTML = `<input type="text" name="data.attributes.attr${nk}.key" value="attr${nk}"/>`;
while ( objKeys.includes(newValue) ) {
++nk;
newValue = `attr${nk}`;
}
newKey.innerHTML = `<input type="text" name="data.attributes.attr${nk}.key" value="${newValue}"/>`;
newKey = newKey.children[0];
form.appendChild(newKey);
await this._onSubmit(event);