las imagenes requeridas solo se pueden reemplazar
This commit is contained in:
parent
1b6599dd40
commit
070ef62806
2 changed files with 11 additions and 8 deletions
|
@ -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
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
|
|
||||||
-# 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']
|
||||||
.custom-control.custom-switch
|
-# Las imágenes requeridas solo se pueden reemplazar
|
||||||
= check_box_tag "#{base}[#{attribute}][path]", '', false, id: "#{base}_#{attribute}_destroy", class: 'custom-control-input'
|
- unless metadata.required
|
||||||
= label_tag "#{base}_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label'
|
.custom-control.custom-switch
|
||||||
|
= 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'
|
||||||
- else
|
- else
|
||||||
= image_tag '',
|
= image_tag '',
|
||||||
alt: metadata.value['description'],
|
alt: metadata.value['description'],
|
||||||
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue