5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 01:26:22 +00:00
panel/app/assets/javascripts/validation.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-06-15 22:13:18 +00:00
$(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) {
2018-06-25 20:36:10 +00:00
if (e.keyCode == 13) {
e.preventDefault();
e.stopPropagation();
}
});
// 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');
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');
});
2018-06-15 22:13:18 +00:00
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');
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
});