green_barrel/fields/
password.rs

1//! Password field.
2
3use core::fmt::Debug;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Clone, Debug)]
7pub struct PasswordField {
8    pub id: String, // The value is determined automatically. Format: "model-name--field-name".
9    pub label: String, // Web form field name.
10    pub field_type: String, // Field type.
11    pub input_type: String, // The value is determined automatically.
12    pub name: String, // The value is determined automatically.
13    pub value: Option<String>, // Sets the value of an element.
14    pub placeholder: String, // Displays prompt text.
15    pub regex: String, // A regular expression to validate the value.
16    pub regex_err_msg: String, // To customize error message.
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 disabled: bool, // Blocks access and modification of the element.
21    pub readonly: bool, // Specifies that the field cannot be modified by the user.
22    pub is_hide: bool, // Hide field from user.
23    /// Example: `r# "autofocus tabindex="some number" size="some number"#`.    
24    pub other_attrs: String,
25    pub css_classes: String, // Example: "class-name-1 class-name-2".
26    pub hint: String,        // Additional explanation for the user.
27    pub warning: String,     // Warning information.
28    pub errors: Vec<String>, // The value is determined automatically.
29    pub group: u32, // To optimize field traversal in the `paladins/check()` method. Hint: It is recommended not to change.
30}
31
32impl Default for PasswordField {
33    fn default() -> Self {
34        Self {
35            id: String::new(),
36            label: String::new(),
37            field_type: String::from("PasswordField"),
38            input_type: String::from("password"),
39            name: String::new(),
40            value: None,
41            placeholder: String::new(),
42            regex: String::from("^[a-zA-Z0-9@#$%^&+=*!~)(]{8,256}$"),
43            regex_err_msg: t!(
44                "allowed_chars",
45                chars = "a-z A-Z 0-9 @ # $ % ^ & + = * ! ~ ) ("
46            ),
47            minlength: 8,
48            maxlength: 256,
49            required: false,
50            disabled: false,
51            readonly: false,
52            is_hide: false,
53            other_attrs: String::new(),
54            css_classes: String::new(),
55            hint: String::new(),
56            warning: String::new(),
57            errors: Vec::new(),
58            group: 1,
59        }
60    }
61}
62
63impl PasswordField {
64    pub fn get(&self) -> Option<String> {
65        self.value.clone()
66    }
67    pub fn set(&mut self, value: &str) {
68        self.value = Some(String::from(value));
69    }
70}