mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 18:36:22 +00:00
los campos pueden ser obligatorios
This commit is contained in:
parent
3e16a6eaeb
commit
eba5e0918a
5 changed files with 25 additions and 11 deletions
12
app/assets/javascripts/validation.js
Normal file
12
app/assets/javascripts/validation.js
Normal 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');
|
||||
});
|
||||
});
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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!'
|
||||
|
|
|
@ -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!'
|
||||
|
|
Loading…
Reference in a new issue