Skip to content

Commit

Permalink
clean up page state upon form reset
Browse files Browse the repository at this point in the history
...as opposed to upon form population with no paletteKey.
  • Loading branch information
AprilSylph committed Feb 28, 2022
1 parent d13e1ec commit 56aaa5e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/options/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const populateForm = ({ paletteKey, paletteData }) => {
paletteForm.dataset.editing = paletteKey;
createdTime.textContent = getTimestamp(paletteKey);
deleteButton.disabled = false;
} else {
delete paletteForm.dataset.editing;
createdTime.textContent = '';
deleteButton.disabled = true;
}

for (const [propertyName, propertyValue] of Object.entries(paletteData)) {
Expand Down Expand Up @@ -97,6 +93,14 @@ const deleteCurrentPalette = async () => {
}
};

const onFormReset = () => {
delete paletteForm.dataset.editing;
createdTime.textContent = '';

disableSaveButton();
deleteButton.disabled = true;
};

const onFormSubmitted = async event => {
event.preventDefault();

Expand Down Expand Up @@ -159,7 +163,7 @@ getBuiltInPaletteList.then(builtInPaletteList => {
));
});

paletteForm.addEventListener('reset', disableSaveButton);
paletteForm.addEventListener('reset', onFormReset);
paletteForm.addEventListener('submit', onFormSubmitted);
paletteForm.addEventListener('input', updatePreview);
paletteForm.reset();
Expand Down

0 comments on commit 56aaa5e

Please sign in to comment.