green_barrel/fields/
ip.rs

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