mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 04:21:41 +00:00
agregar grupos de checkboxes
This commit is contained in:
parent
33eacbbc58
commit
6dd7b2a85f
3 changed files with 19 additions and 1 deletions
|
@ -327,7 +327,7 @@ class Post
|
|||
|
||||
# Como get_front_matter pero con un valor por defecto
|
||||
def fetch_front_matter(name, default)
|
||||
@front_matter.fetch(name, default)
|
||||
get_front_matter(name) || default
|
||||
end
|
||||
|
||||
# Trae el template a partir del layout
|
||||
|
|
|
@ -56,6 +56,8 @@ class Post
|
|||
@type = 'year'
|
||||
when text_area?
|
||||
@type = 'text_area'
|
||||
when check_box_group?
|
||||
@type = 'check_box_group'
|
||||
when string?
|
||||
@type = 'text'
|
||||
# TODO volver a hacer funcionar esto y ahorranos los multiple:
|
||||
|
@ -176,6 +178,10 @@ class Post
|
|||
{ key => empty_value }
|
||||
end
|
||||
|
||||
def check_box_group?
|
||||
array? && contents.fetch('checkbox', false)
|
||||
end
|
||||
|
||||
def array?
|
||||
value.is_a? Array
|
||||
end
|
||||
|
|
12
app/views/posts/template_field/_check_box_group.haml
Normal file
12
app/views/posts/template_field/_check_box_group.haml
Normal file
|
@ -0,0 +1,12 @@
|
|||
-# Obtener el nombre del campo
|
||||
- field_name = field_name_for_post_as_string(name)
|
||||
-# Obtener todos los valores
|
||||
- value = [] if value.nil?
|
||||
- values = template.values.empty? ? [value].flatten : template.values
|
||||
- values.each do |v|
|
||||
.form-check
|
||||
= check_box_tag field_name+'[]',
|
||||
v,
|
||||
@post.fetch_front_matter(name, []).include?(v),
|
||||
class: 'form-check-input'
|
||||
= label_tag field_name, v, class: 'form-check-label'
|
Loading…
Reference in a new issue