2018-06-15 22:13:18 +00:00
|
|
|
$(document).on('turbolinks:load', function() {
|
2019-08-13 19:09:23 +00:00
|
|
|
// Previene el envío del formulario al presionar <Enter>
|
2019-07-08 21:13:03 +00:00
|
|
|
$(document).on('keypress', '.post :input:not(textarea):not([type=submit])', function(e) {
|
2018-06-25 20:36:10 +00:00
|
|
|
if (e.keyCode == 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-13 19:09:23 +00:00
|
|
|
// Al enviar el formulario del artículo, aplicar la validación
|
2018-07-23 14:26:40 +00:00
|
|
|
$('.submit-post').click(function(e) {
|
2018-06-15 22:13:18 +00:00
|
|
|
var form = $(this).parents('form.form');
|
2018-12-14 13:32:35 +00:00
|
|
|
var invalid_help = $('.invalid_help');
|
2018-12-14 13:38:50 +00:00
|
|
|
var sending_help = $('.sending_help');
|
2018-12-14 13:32:35 +00:00
|
|
|
|
|
|
|
invalid_help.addClass('d-none');
|
2018-12-14 13:38:50 +00:00
|
|
|
sending_help.addClass('d-none');
|
2019-08-13 19:09:23 +00:00
|
|
|
form.find('[aria-invalid="true"]')
|
|
|
|
.attr('aria-invalid', false)
|
|
|
|
.attr('aria-describedby', function() {
|
|
|
|
return $(this).siblings('.feedback').attr('id');
|
|
|
|
});
|
2018-06-15 22:13:18 +00:00
|
|
|
|
|
|
|
if (form[0].checkValidity() === false) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-12-14 13:32:35 +00:00
|
|
|
invalid_help.removeClass('d-none');
|
2019-08-13 19:09:23 +00:00
|
|
|
|
|
|
|
form.find(':invalid')
|
|
|
|
.attr('aria-invalid', true)
|
|
|
|
.attr('aria-describedby', function() {
|
|
|
|
return $(this).siblings('.invalid-feedback').attr('id');
|
|
|
|
});
|
2018-12-14 13:38:50 +00:00
|
|
|
} else {
|
|
|
|
sending_help.removeClass('d-none');
|
2018-06-15 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form.addClass('was-validated');
|
|
|
|
});
|
2018-12-14 15:12:17 +00:00
|
|
|
|
|
|
|
$('.submit-post-incomplete').click(function(e) {
|
|
|
|
$('.sending_help').removeClass('d-none');
|
|
|
|
});
|
2018-06-15 22:13:18 +00:00
|
|
|
});
|