public inbox for yew-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit 2/2] widget: selector: don't autoselect or set to default more than once
Date: Thu, 18 Jun 2026 16:44:18 +0200	[thread overview]
Message-ID: <20260618144425.3901589-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260618144425.3901589-1-d.csapak@proxmox.com>

Autoselect or setting the default should only happen once, otherwise
clearing e.g. a combobox and trying to open the picker (which sets a
filter+sorter, which triggers a DataChange event) sets it back to the
default instead of opening it.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/widget/form/selector.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/widget/form/selector.rs b/src/widget/form/selector.rs
index 018d34f..1878a89 100644
--- a/src/widget/form/selector.rs
+++ b/src/widget/form/selector.rs
@@ -165,6 +165,7 @@ pub enum Msg<S: DataStore> {
 pub struct SelectorField<S: DataStore> {
     state: ManagedFieldState,
     selection: Selection,
+    value_set: bool,
     load_error: Option<String>,
     _store_observer: S::Observer,
     abort_load_guard: Option<AsyncAbortGuard>,
@@ -278,6 +279,7 @@ impl<S: DataStore + 'static> ManagedField for SelectorField<S> {
         let mut me = Self {
             state: ManagedFieldState::new(value, default),
             selection,
+            value_set: false,
             load_error: None,
             _store_observer,
             abort_load_guard: None,
@@ -329,7 +331,7 @@ impl<S: DataStore + 'static> ManagedField for SelectorField<S> {
             Msg::DataChange => {
                 let value = self.value.as_str().unwrap_or("").to_owned();
 
-                if self.load_error.is_none() && value.is_empty() {
+                if self.load_error.is_none() && value.is_empty() && !self.value_set {
                     let mut default = props.default.clone();
 
                     if default.is_none() && props.autoselect {
@@ -341,6 +343,7 @@ impl<S: DataStore + 'static> ManagedField for SelectorField<S> {
                     if let Some(default) = default {
                         ctx.link().update_value(default.to_string());
                         ctx.link().update_default(default.to_string());
+                        self.value_set = true;
                     }
                 }
                 ctx.link().validate(); // re-evaluate
-- 
2.47.3





  reply	other threads:[~2026-06-18 14:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18 14:44 [PATCH yew-widget-toolkit 1/2] widget: search dropdown: enable hovering style Dominik Csapak
2026-06-18 14:44 ` Dominik Csapak [this message]
2026-06-19  4:59   ` applied: [PATCH yew-widget-toolkit 2/2] widget: selector: don't autoselect or set to default more than once Dietmar Maurer
2026-06-19  4:59 ` applied: [PATCH yew-widget-toolkit 1/2] widget: search dropdown: enable hovering style Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260618144425.3901589-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=yew-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal