[pdm-devel] [PATCH yew-widget-toolkit v3 1/1] props: add readonly to field_std_props

Shannon Sterz s.sterz at proxmox.com
Fri Oct 17 14:46:41 CEST 2025


this allows using the attribute `readonly` to mark a field as
immutable [1]. marking a field as `readonly` as opposed to disabled,
allows users to still select the value and should not be displayed
greyed out.

[1]:
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/readonly

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 src/props/field_builder.rs   | 11 +++++++++++
 src/props/field_std_props.rs | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/src/props/field_builder.rs b/src/props/field_builder.rs
index 38cfb0ca..2584ea85 100644
--- a/src/props/field_builder.rs
+++ b/src/props/field_builder.rs
@@ -132,4 +132,15 @@ pub trait FieldBuilder: Into<VNode> {
     fn set_placeholder(&mut self, placeholder: impl IntoPropValue<Option<AttrValue>>) {
         self.as_input_props_mut().placeholder = placeholder.into_prop_value();
     }
+
+    /// Builder style method to set the `readonly` flag
+    fn read_only(mut self, read_only: bool) -> Self {
+        self.set_read_only(read_only);
+        self
+    }
+
+    /// Method to set the `readonly` flag
+    fn set_read_only(&mut self, read_only: bool) {
+        self.as_input_props_mut().read_only = read_only;
+    }
 }
diff --git a/src/props/field_std_props.rs b/src/props/field_std_props.rs
index 5a4d1fd0..8d6cee47 100644
--- a/src/props/field_std_props.rs
+++ b/src/props/field_std_props.rs
@@ -46,6 +46,10 @@ pub struct FieldStdProps {
     /// empty.
     #[prop_or_default]
     pub submit_empty: bool,
+
+    /// Marks as a field as read-only. Allows users to still select a field, but not edit it.
+    #[prop_or_default]
+    pub read_only: bool,
 }
 
 impl Default for FieldStdProps {
@@ -90,6 +94,13 @@ impl FieldStdProps {
             );
         }
 
+        if self.read_only {
+            attr_map.insert(
+                AttrValue::Static("readonly"),
+                (AttrValue::Static(""), ApplyAttributeAs::Attribute),
+            );
+        }
+
         if let Some(ref aria_label) = self.aria_label {
             attr_map.insert(
                 AttrValue::Static("aria-label"),
-- 
2.47.3





More information about the pdm-devel mailing list