green_barrel/fields/
date.rs

1//! A field for entering a date in the format **1970-01-01**.
2
3use core::fmt::Debug;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Clone, Debug)]
7pub struct DateField {
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. Example: 1970-01-01
14    pub default: Option<String>, // Value by default Example: 1970-01-01
15    pub placeholder: String, // Displays prompt text.
16    pub required: bool, // Mandatory field.
17    pub unique: bool, // The unique value of a field in a collection.
18    pub disabled: bool, // Blocks access and modification of the element.
19    pub readonly: bool, // Specifies that the field cannot be modified by the user.
20    pub min: String, // The lower value for entering a date.
21    pub max: String, // The top value for entering a date.
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 DateField {
33    fn default() -> Self {
34        Self {
35            id: String::new(),
36            label: String::new(),
37            field_type: String::from("DateField"),
38            input_type: String::from("date"),
39            name: String::new(),
40            value: None,
41            default: None,
42            placeholder: String::new(),
43            required: false,
44            unique: false,
45            disabled: false,
46            readonly: false,
47            min: String::new(),
48            max: String::new(),
49            is_hide: false,
50            other_attrs: String::new(),
51            css_classes: String::new(),
52            hint: t!("format", sample = "yyyy-mm-dd"),
53            warning: String::new(),
54            errors: Vec::new(),
55            group: 3,
56        }
57    }
58}
59
60impl DateField {
61    pub fn get(&self) -> Option<String> {
62        self.value.clone()
63    }
64    pub fn set(&mut self, value: &str) {
65        self.value = Some(String::from(value));
66    }
67}