瀏覽代碼

add checked to form

Jonathan Kelley 1 年之前
父節點
當前提交
2366d609d4
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      packages/html/src/events/form.rs

+ 8 - 0
packages/html/src/events/form.rs

@@ -90,6 +90,14 @@ impl FormData {
         self.inner.value()
         self.inner.value()
     }
     }
 
 
+    /// Try to parse the value as a boolean
+    ///
+    /// Returns false if the value is not a boolean, or if it is false!
+    /// Does not verify anything about the event itself, use with caution
+    pub fn checked(&self) -> bool {
+        self.value().parse().unwrap_or(false)
+    }
+
     /// Get the values of the form event
     /// Get the values of the form event
     pub fn values(&self) -> HashMap<String, FormValue> {
     pub fn values(&self) -> HashMap<String, FormValue> {
         self.inner.values()
         self.inner.values()