mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Validate entries in editors
This commit is contained in:
parent
24f493d7d6
commit
e0619b6b27
8 changed files with 173 additions and 66 deletions
|
|
@ -75,11 +75,22 @@ impl Screen<Option<Instrument>, Instrument> for InstrumentEditor {
|
|||
});
|
||||
}));
|
||||
|
||||
this.name
|
||||
.entry
|
||||
.connect_changed(clone!(@weak this => move |_| this.validate()));
|
||||
|
||||
this.validate();
|
||||
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl InstrumentEditor {
|
||||
/// Validate inputs and enable/disable saving.
|
||||
fn validate(&self) {
|
||||
self.editor.set_may_save(!self.name.get_text().is_empty());
|
||||
}
|
||||
|
||||
/// Save the instrument and possibly upload it to the server.
|
||||
async fn save(&self) -> Result<Instrument> {
|
||||
let name = self.name.get_text();
|
||||
|
|
@ -90,10 +101,18 @@ impl InstrumentEditor {
|
|||
};
|
||||
|
||||
if self.upload.get_active() {
|
||||
self.handle.backend.cl().post_instrument(&instrument).await?;
|
||||
self.handle
|
||||
.backend
|
||||
.cl()
|
||||
.post_instrument(&instrument)
|
||||
.await?;
|
||||
}
|
||||
|
||||
self.handle.backend.db().update_instrument(instrument.clone()).await?;
|
||||
self.handle
|
||||
.backend
|
||||
.db()
|
||||
.update_instrument(instrument.clone())
|
||||
.await?;
|
||||
self.handle.backend.library_changed();
|
||||
|
||||
Ok(instrument)
|
||||
|
|
@ -105,4 +124,3 @@ impl Widget for InstrumentEditor {
|
|||
self.editor.widget.clone().upcast()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue