5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 23:36:21 +00:00

validar fechas en navegadores que no las soportan

closes 168
This commit is contained in:
f 2021-02-11 17:49:49 -03:00
parent 2fb79ffa15
commit 17d0ab6df3
5 changed files with 19 additions and 4 deletions

View file

@ -107,4 +107,13 @@ document.addEventListener('turbolinks:load', () => {
// Ocultar el area // Ocultar el area
textArea.style.display = 'none' textArea.style.display = 'none'
}) })
// Validar fechas en navegadores que no soportan date
document.querySelectorAll('input[type="date"]').forEach(date => {
if (date.type === 'date') return
date.addEventListener('change', event => {
date.setCustomValidity(date.validity.patternMismatch ? date.dataset.patternMismatch : '')
})
})
}) })

View file

@ -1,6 +1,7 @@
.form-group .form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post) = label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= date_field base, attribute, value: metadata.value.to_date.strftime('%F'), = date_field base, attribute, value: metadata.value.to_date.strftime('%F'),
**field_options(attribute, metadata) **field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}',
data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
= render 'posts/attribute_feedback', = render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata post: post, attribute: attribute, metadata: metadata

View file

@ -1,6 +1,7 @@
.form-group .form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post) = label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= date_field base, attribute, value: metadata.value.strftime('%F'), = date_field base, attribute, value: metadata.value.strftime('%F'),
**field_options(attribute, metadata) **field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}',
data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
= render 'posts/attribute_feedback', = render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata post: post, attribute: attribute, metadata: metadata

View file

@ -50,6 +50,8 @@ en:
missing_post: "Couldn't find the related post" missing_post: "Couldn't find the related post"
has_many: has_many:
missing_posts: "Couldn't find some related posts" missing_posts: "Couldn't find some related posts"
date:
invalid_format: "It seems that your browser doesn't support dates and the date is on the incorrect format, please use yyyy-mm-dd, ie. 2021-01-31"
exceptions: exceptions:
post: post:
site_missing: 'Needs an instance of Site' site_missing: 'Needs an instance of Site'
@ -462,7 +464,7 @@ en:
label: Language label: Language
date: date:
label: Date label: Date
help: Publication date for this post. If you use a date in the future the post won't be published until then. help: Date for this post. If you use a date in the future the post won't be published until you publish changes on that day.
required: required:
label: ' (required)' label: ' (required)'
feedback: 'This field cannot be empty!' feedback: 'This field cannot be empty!'

View file

@ -50,6 +50,8 @@ es:
missing_post: 'No se pudo encontrar el artículo relacionado' missing_post: 'No se pudo encontrar el artículo relacionado'
has_many: has_many:
missing_posts: 'No se pudieron encontrar algunos artículos relacionados' missing_posts: 'No se pudieron encontrar algunos artículos relacionados'
date:
invalid_format: 'Parece que tu navegador no soporta fechas y la fecha no está en el formato correcto, por favor usa aaaa-mm-dd, por ejemplo: 2021-01-31'
exceptions: exceptions:
post: post:
site_missing: 'Necesita una instancia de Site' site_missing: 'Necesita una instancia de Site'
@ -471,7 +473,7 @@ es:
label: Idioma label: Idioma
date: date:
label: Fecha label: Fecha
help: La fecha de publicación del artículo. Si colocas una fecha en el futuro no se publicará hasta ese día. help: La fecha del artículo. Si colocas una fecha en el futuro no se publicará hasta que publiques cambios ese día.
required: required:
label: ' (requerido)' label: ' (requerido)'
feedback: '¡Este campo no puede estar vacío!' feedback: '¡Este campo no puede estar vacío!'