From d119c9a2fb65f79bb0a531014471e61220e94d6c Mon Sep 17 00:00:00 2001 From: f Date: Tue, 19 Jun 2018 13:50:39 -0300 Subject: [PATCH] indicar cuando un campo es obligatorio --- app/models/post/template_field.rb | 7 +++++++ app/views/posts/_form.haml | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index 9a09364..462cb32 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -107,6 +107,13 @@ class Post contents.fetch('open', value.count < 2) end + def human + h = key.humanize + h = h + ' *' if required? + + h + end + # Obtiene los valores posibles para el campo de la plantilla def values return '' if %w[string text].include? value diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index cbe0539..45dd74d 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -78,7 +78,7 @@ - @post.template_fields.each do |template| - next unless type = template.type .form-group - = label_tag "post_#{template}", template.to_s.humanize + = label_tag "post_#{template}", template.human - name = "post[#{template}]" - value = @post.new? ? template.values : @post.get_front_matter(template) - case type @@ -96,6 +96,7 @@ = select_tag name, options_for_select(template.values, @post.get_front_matter(template)), { class: 'form-control select2', multiple: template.multiple?, + required: template.required?, data: { tags: template.open?, placeholder: t('posts.select.placeholder')}} - if template.open?