From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 7DB1A1FF16F for ; Tue, 30 Sep 2025 15:00:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AAB187A23; Tue, 30 Sep 2025 15:00:47 +0200 (CEST) From: Hannes Laimer To: pdm-devel@lists.proxmox.com Date: Tue, 30 Sep 2025 14:59:58 +0200 Message-ID: <20250930125958.309839-1-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759237188998 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.045 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [RFC pwt] combobox: add .schema() to builder X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" ... guarded by the `proxmox-schema` feature. Signed-off-by: Hannes Laimer --- Very much RFC! Is there a reason to not have this on most elements? This patch is exemplary, we just pull enum items and default value out of the schema for the comobox. We could do the same for descriptions or regex formats. Cargo.toml | 5 ++++ src/widget/form/combobox.rs | 46 +++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86f73cc..b2d2f1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,4 +71,9 @@ url = "2.1" percent-encoding = "2.1" gettext = "0.4" +proxmox-schema = { version = "5.0.0", optional = true } pwt-macros = { version = "0.5", path = "pwt-macros" } + +[features] +default = ["proxmox-schema"] +proxmox-schema = ["dep:proxmox-schema"] diff --git a/src/widget/form/combobox.rs b/src/widget/form/combobox.rs index fc402ba..167fdb4 100644 --- a/src/widget/form/combobox.rs +++ b/src/widget/form/combobox.rs @@ -7,8 +7,8 @@ use yew::html::{IntoEventCallback, IntoPropValue}; use yew::prelude::*; use yew::virtual_dom::Key; -// #[cfg(feature = "proxmox-schema")] -// use proxmox_schema::Schema; +#[cfg(feature = "proxmox-schema")] +use proxmox_schema::Schema; use crate::prelude::*; use crate::props::{IntoOptionalRenderFn, IntoTextFilterFn, RenderFn, TextFilterFn}; @@ -164,21 +164,33 @@ impl Combobox { self.validate = validate.into_validate_fn(); } - // /// Builder style method to set the validation schema - // #[cfg(feature = "proxmox-schema")] - // pub fn schema(mut self, schema: &'static Schema) -> Self { - // self.set_schema(schema); - // self - // } - - // /// Method to set the validation schema - // #[cfg(feature = "proxmox-schema")] - // pub fn set_schema(&mut self, schema: &'static Schema) { - // self.set_validate(move |(value, _store): &(String, _)| { - // schema.parse_simple_value(value)?; - // Ok(()) - // }); - // } + /// Builder style method to set the validation schema, items and placeholder + #[cfg(feature = "proxmox-schema")] + pub fn schema(mut self, schema: &'static Schema) -> Self { + self.set_schema(schema); + self + } + + /// Method to set the validation schema, items and placeholder + #[cfg(feature = "proxmox-schema")] + pub fn set_schema(&mut self, schema: &'static Schema) { + if let proxmox_schema::Schema::String(s) = schema { + if let Some(proxmox_schema::ApiStringFormat::Enum(e)) = s.format { + let items: Vec = e + .iter() + .map(|entry| entry.value.to_string().into()) + .collect(); + self.set_items(items.into()); + } + if let Some(value) = s.default { + self.set_placeholder(value); + } + } + self.set_validate(move |(value, _store): &(String, _)| { + schema.parse_simple_value(value)?; + Ok(()) + }); + } /// Builder style method to add an trigger pub fn with_trigger(mut self, trigger: impl Into, right: bool) -> Self { -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel