los campos pueden ser obligatorios

This commit is contained in:
f 2018-06-15 19:13:18 -03:00
parent 3e16a6eaeb
commit eba5e0918a
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
5 changed files with 25 additions and 11 deletions

View file

@ -0,0 +1,12 @@
$(document).on('turbolinks:load', function() {
$('#submit-post').click(function(e) {
var form = $(this).parents('form.form');
if (form[0].checkValidity() === false) {
e.preventDefault();
e.stopPropagation();
}
form.addClass('was-validated');
});
});

View file

@ -10,9 +10,13 @@ class Post
@contents = contents
end
# Obtiene el valor
def value
complex? ? contents.dig('value') : contents
end
def type
return @type if @type
return unless simple?
case
when text_area?
@ -79,11 +83,6 @@ class Post
array?
end
# Obtiene el valor
def value
complex? ? contents.dig('value') : contents
end
# Obtiene los valores posibles para el campo de la plantilla
def values
return '' if %w[string text].include? value

View file

@ -15,7 +15,7 @@
- else
- url = site_post_path(@site, @post, lang: @lang)
- method = :patch
= form_tag url, method: method, class: 'form' do
= form_tag url, method: method, class: 'form', novalidate: true do
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success'
.form-group
@ -85,9 +85,10 @@
- when 'text'
= text_field 'post', template,
value: value,
class: 'form-control'
class: 'form-control',
required: template.required?
- when 'text_area'
= text_area_tag name, value, class: 'form-control'
= text_area_tag name, value, class: 'form-control', required: template.required?
- when 'check_box'
= hidden_field 'post', template, value: 'false'
= check_box_tag name, 'true', value == 'true', class: 'form-control'
@ -95,5 +96,6 @@
= select_tag name, options_for_select(template.values, @post.get_front_matter(template)),
{ class: 'form-control select2',
multiple: template.multiple? }
.invalid-feedback= t('posts.invalid')
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success'
= submit_tag t('posts.save'), class: 'btn btn-success', id: 'submit-post'

View file

@ -202,4 +202,4 @@ en:
file: "Couldn't write the file"
title: 'Post needs a title'
date: 'Post needs a valid date'
invalid: 'This field is required!'

View file

@ -198,3 +198,4 @@ es:
file: 'No se pudo escribir el archivo'
title: 'Necesita un título'
date: 'Necesita una fecha'
invalid: '¡Este campo es obligatorio!'