las imagenes requeridas solo se pueden reemplazar

This commit is contained in:
f 2021-02-24 16:31:57 -03:00
parent 1b6599dd40
commit 070ef62806
2 changed files with 11 additions and 8 deletions

View file

@ -92,10 +92,11 @@ module ApplicationHelper
end end
# Busca la traducción de una etiqueta en los metadatos de un post # Busca la traducción de una etiqueta en los metadatos de un post
def post_label_t(*attribute, post:) def post_label_t(*attribute, post:, **extra)
label = post_t(*attribute, post: post, type: :label) required = extra.key?(:required) ? extra[:required] : post[attribute.first].required
label += I18n.t('posts.attributes.required.label') if post.send(attribute.first).required label = post_t(*attribute, post: post, type: :label)
label += I18n.t('posts.attributes.required.label') if required
label label
end end

View file

@ -7,6 +7,8 @@
-# Mantener el valor si no enviamos ninguna imagen -# Mantener el valor si no enviamos ninguna imagen
= hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path'] = hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path']
-# Las imágenes requeridas solo se pueden reemplazar
- unless metadata.required
.custom-control.custom-switch .custom-control.custom-switch
= check_box_tag "#{base}[#{attribute}][path]", '', false, id: "#{base}_#{attribute}_destroy", class: 'custom-control-input' = check_box_tag "#{base}[#{attribute}][path]", '', false, id: "#{base}_#{attribute}_destroy", class: 'custom-control-input'
= label_tag "#{base}_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label' = label_tag "#{base}_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label'
@ -18,7 +20,7 @@
.custom-file .custom-file
= file_field(*field_name_for(base, attribute, :path), = file_field(*field_name_for(base, attribute, :path),
**field_options(attribute, metadata), **field_options(attribute, metadata, required: (metadata.required && !metadata.path?)),
class: "custom-file-input #{invalid(post, attribute)}", class: "custom-file-input #{invalid(post, attribute)}",
accept: 'image/*', data: { preview: "#{attribute}-preview" }) accept: 'image/*', data: { preview: "#{attribute}-preview" })
= label_tag "#{base}_#{attribute}_path", = label_tag "#{base}_#{attribute}_path",
@ -28,7 +30,7 @@
.form-group .form-group
= label_tag "#{base}_#{attribute}_description", = label_tag "#{base}_#{attribute}_description",
post_label_t(attribute, :description, post: post) post_label_t(attribute, :description, post: post, required: false)
= text_field(*field_name_for(base, attribute, :description), = text_field(*field_name_for(base, attribute, :description),
value: metadata.value['description'], value: metadata.value['description'],
dir: dir, lang: locale, dir: dir, lang: locale,