Created a dirty site variable and cloned the edited site. Fixes the focus bug and prevents unsaved changes from appearing in the table after cancelling the editor.

This commit is contained in:
2022-06-15 11:46:14 -07:00
parent 69ca0d5eb6
commit a49a34f132

View File

@@ -48,14 +48,19 @@
const deleteSite = site => {
//TODO:
};
// Create a holder for the site being edited. This allows us to clear the editor when the user finishes, and allows the table or parent view to setup the editor.
let editedSite = writable(null);
let dirtySite = null;
// Copy the edited site when ever it changes, set some defaults for a new site object (to make the view happy).
editedSite.subscribe(site => {dirtySite = Object.assign({name: ""}, site)});
// Load the sites (reactive).
let sites = Sites.find({});
const applySiteChanges = () => {
if($editedSite._id)
Meteor.call("sites.update", $editedSite._id,$editedSite.name);
if(dirtySite._id)
Meteor.call("sites.update", dirtySite._id, dirtySite.name);
else
Meteor.call("sites.add", $editedSite.name);
Meteor.call("sites.add", dirtySite.name);
editedSite.set(null);
}
const rejectSiteChanges = () => {
@@ -65,10 +70,10 @@
<div class="container">
<GridTable bind:rows={sites} columns="{siteColumns}" actions="{actions}" rowKey="{(user) => {return user._id}}" bind:edited="{editedSite}">
{#if $editedSite}
{#if dirtySite}
<div class="editorContainer">
<div style="grid-column: 1/span 1">
<TextField type="text" style="width: 100%" bind:value={$editedSite.name} label="Name">
<TextField type="text" style="width: 100%" bind:value={dirtySite.name} label="Name">
<HelperText slot="helper">Provide a unique name for the site.</HelperText>
</TextField>
</div>