agregar grupos de checkboxes

This commit is contained in:
f 2018-12-14 13:04:45 -03:00
parent 33eacbbc58
commit 6dd7b2a85f
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
3 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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

View 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'