mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 21:16:22 +00:00
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
$(document).on('turbolinks:load', function() {
|
|
// Previene el envío del formulario al presionar <Enter>
|
|
$(document).on('keypress', '.post :input:not(textarea):not([type=submit])', function(e) {
|
|
if (e.keyCode == 13) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
});
|
|
|
|
// Al enviar el formulario del artículo, aplicar la validación
|
|
$('.submit-post').click(function(e) {
|
|
var form = $(this).parents('form.form');
|
|
var invalid_help = $('.invalid_help');
|
|
var sending_help = $('.sending_help');
|
|
|
|
invalid_help.addClass('d-none');
|
|
sending_help.addClass('d-none');
|
|
form.find('[aria-invalid="true"]')
|
|
.attr('aria-invalid', false)
|
|
.attr('aria-describedby', function() {
|
|
return $(this).siblings('.feedback').attr('id');
|
|
});
|
|
|
|
if (form[0].checkValidity() === false) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
invalid_help.removeClass('d-none');
|
|
|
|
form.find(':invalid')
|
|
.attr('aria-invalid', true)
|
|
.attr('aria-describedby', function() {
|
|
return $(this).siblings('.invalid-feedback').attr('id');
|
|
});
|
|
} else {
|
|
sending_help.removeClass('d-none');
|
|
}
|
|
|
|
form.addClass('was-validated');
|
|
});
|
|
|
|
$('.submit-post-incomplete').click(function(e) {
|
|
$('.sending_help').removeClass('d-none');
|
|
});
|
|
});
|