mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 01:41:42 +00:00
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
|
||||
|
||||
# Busca la traducción de una etiqueta en los metadatos de un post
|
||||
def post_label_t(*attribute, post:)
|
||||
label = post_t(*attribute, post: post, type: :label)
|
||||
def post_label_t(*attribute, post:, **extra)
|
||||
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
|
||||
end
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
-# Mantener el valor si no enviamos ninguna imagen
|
||||
= hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path']
|
||||
.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'
|
||||
-# Las imágenes requeridas solo se pueden reemplazar
|
||||
- unless metadata.required
|
||||
.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
|
||||
= image_tag '',
|
||||
alt: metadata.value['description'],
|
||||
|
@ -18,7 +20,7 @@
|
|||
|
||||
.custom-file
|
||||
= 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)}",
|
||||
accept: 'image/*', data: { preview: "#{attribute}-preview" })
|
||||
= label_tag "#{base}_#{attribute}_path",
|
||||
|
@ -28,7 +30,7 @@
|
|||
|
||||
.form-group
|
||||
= 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),
|
||||
value: metadata.value['description'],
|
||||
dir: dir, lang: locale,
|
||||
|
|
Loading…
Reference in a new issue