green_barrel/fields/choice_text.rs
1//! Type of selective field with static of elements.
2//! With a single choice.
3
4use core::fmt::Debug;
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Clone, Debug)]
8pub struct ChoiceTextField {
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.
12 pub name: String, // The value is determined automatically.
13 pub value: Option<String>, // Sets the value of an element.
14 pub default: Option<String>, // Value by default.
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 multiple: String, // Specifies that multiple options can be selected at once. Changing the default value is not recommended.
21 pub choices: Vec<(String, String)>, // Html tag: <option value="value">Title</option> ; Example: vec![("value", "Title"), ("value 2", "Title 2")].
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 ChoiceTextField {
33 fn default() -> Self {
34 Self {
35 id: String::new(),
36 label: String::new(),
37 field_type: String::from("ChoiceTextField"),
38 name: String::new(),
39 value: None,
40 default: None,
41 placeholder: String::new(),
42 required: false,
43 unique: false,
44 disabled: false,
45 readonly: false,
46 // Changing the default value is not recommended.
47 multiple: String::new(),
48 choices: Vec::new(),
49 is_hide: false,
50 other_attrs: String::new(),
51 css_classes: String::new(),
52 hint: String::new(),
53 warning: String::new(),
54 errors: Vec::new(),
55 group: 4,
56 }
57 }
58}
59
60impl ChoiceTextField {
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}