green_barrel/fields/
bool.rs

1//! Boolean field.
2
3use core::fmt::Debug;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Clone, Debug)]
7pub struct BoolField {
8    /// The value is determined automatically.
9    /// Format: "model-name--field-name".
10    pub id: String,
11    /// Web form field name.
12    pub label: String,
13    /// Field type.
14    pub field_type: String,
15    /// The value is determined automatically.
16    pub input_type: String,
17    /// The value is determined automatically.
18    pub name: String,
19    /// Sets the value of an element.
20    pub value: Option<bool>,
21    /// Value by default
22    pub default: Option<bool>,
23    /// Displays prompt text.
24    pub placeholder: String,
25    /// Blocks access and modification of the element.
26    pub disabled: bool,
27    /// Specifies that the field cannot be modified by the user.
28    pub readonly: bool,
29    /// Hide field from user.
30    pub is_hide: bool,
31    /// Example: `r# "autofocus tabindex="some number" size="some number"#`.    
32    pub other_attrs: String,
33    /// Example: "class-name-1 class-name-2".
34    pub css_classes: String,
35    /// Additional explanation for the user.
36    pub hint: String,
37    /// Warning information.
38    pub warning: String,
39    /// The value is determined automatically.
40    pub errors: Vec<String>,
41    /// To optimize field traversal in the `paladins/check()` method.
42    /// Hint: It is recommended not to change.
43    pub group: u32,
44}
45
46impl Default for BoolField {
47    fn default() -> Self {
48        Self {
49            id: String::new(),
50            label: String::new(),
51            field_type: String::from("BoolField"),
52            input_type: String::from("checkbox"),
53            name: String::new(),
54            value: None,
55            default: Some(false),
56            placeholder: String::new(),
57            disabled: false,
58            readonly: false,
59            is_hide: false,
60            other_attrs: String::new(),
61            css_classes: String::new(),
62            hint: String::new(),
63            warning: String::new(),
64            errors: Vec::new(),
65            group: 13,
66        }
67    }
68}
69
70impl BoolField {
71    /// Getter
72    pub fn get(&self) -> Option<bool> {
73        self.value
74    }
75    /// Setter
76    pub fn set(&mut self, value: bool) {
77        self.value = Some(value);
78    }
79}