Added inline property to Radio field.
authorAndrea Zagli <azagli@libero.it>
Sat, 7 Oct 2023 07:12:26 +0000 (09:12 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 7 Oct 2023 07:12:26 +0000 (09:12 +0200)
src/fields.rs

index 0ee91d4f445af8555b6c6e8ccbee32d9587b4798..57ac3350386d71f9dad653259c677165878d0e81 100644 (file)
@@ -435,6 +435,7 @@ pub struct FOption {
 #[derive(Default)]
 pub struct FieldRadio {
        field: Field,
+       inline: bool,
        options: Vec<FOption>,
 }
 
@@ -554,6 +555,7 @@ impl TField for FieldRadio {
                context.insert("help", &self.field.help);
                context.insert("class", &self.field.class);
                context.insert("value", &self.field.value);
+               context.insert("inline", &self.inline);
                context.insert("options", &self.options);
                s.push_str(self.field.tmpl.render("field", &context).unwrap().as_str());
 
@@ -578,7 +580,7 @@ impl FieldRadio {
                match f.field.tmpl.add_raw_template("field", r#"{% if label %}<div class="mb-3">
  <label for="{{ name }}" class="form-label">{{ label }}</label><br/>{% endif %}
  {% for o in options %}
- <div class="form-check{% if help %} is-invalid{% endif %}">
+ <div class="form-check{% if inline %} form-check-inline{% endif %}{% if help %} is-invalid{% endif %}">
  <input type="radio" class="form-check-input{% if help %} is-invalid{% endif %}{% if class %} {{ class }}{% endif %}" name="{{ name }}" id="{{ name }}_{{ loop.index }}" value="{{ o.value }}"{% if value == o.value %} checked{% endif %}/>
  <label class="form-label" for="{{ name }}_{{ loop.index }}">{{ o.label }}</label>
  </div>
@@ -590,7 +592,7 @@ _ => {},
 };
 
                match f.field.tmpl.add_raw_template("field_single", r#"<div class="form-check{% if help %} is-invalid{% endif %}">
- <input type="radio" class="form-check-input{% if help %} is-invalid{% endif %}{% if class %} {{ class }}{% endif %}" name="{{ name }}" id="{{ name }}_{{ idx }}" value="{{ value }}"{% if checked != "" %} checked{% endif %}/>
+ <input type="radio" class="form-check-input{% if inline %} form-check-inline{% endif %}{% if help %} is-invalid{% endif %}{% if class %} {{ class }}{% endif %}" name="{{ name }}" id="{{ name }}_{{ idx }}" value="{{ value }}"{% if checked != "" %} checked{% endif %}/>
  <label class="form-label" for="{{ name }}_{{ idx }}">{{ label }}</label>
  </div>"#) {
 Err(e) => { println!("{:?}", e) },
@@ -600,6 +602,14 @@ _ => {},
                f
        }
 
+       pub fn get_inline(&self) -> bool {
+               self.inline
+       }
+
+       pub fn set_inline(&mut self, inline: bool) {
+               self.inline = inline;
+       }
+
        pub fn add_option(&mut self, option: FOption) {
                self.options.push(option);
        }