Merge branch '3-fix-add-remove-attr' into 'master'

3: Fix issue with adding and removing attributes

Closes #3

See merge request foundrynet/worldbuilding!6
This commit is contained in:
Andrew 2020-08-10 03:47:14 +00:00
commit ef009146f2
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);