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