green_barrel/fields/
color.rs

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