demarches-normaliennes/app/assets/javascripts/new_design/champs/siret.js
2018-04-17 13:49:02 +02:00

30 lines
848 B
JavaScript

document.addEventListener('turbolinks:load', function() {
$('[data-siret]').on('input', function(evt) {
var input = $(evt.target);
var value = input.val();
var url = input.attr('data-siret');
switch (value.length) {
case 0:
$.get(url+'?siret=blank');
break;
case 14:
input.attr('disabled', 'disabled');
$('.spinner').show();
$.get(url+'?siret='+value).then(function() {
input.removeAttr('data-invalid');
input.removeAttr('disabled');
$('.spinner').hide();
}, function() {
input.removeAttr('disabled');
input.attr('data-invalid', true);
$('.spinner').hide();
});
break;
default:
if (!input.attr('data-invalid')) {
input.attr('data-invalid', true);
$.get(url+'?siret=invalid');
}
}
});
});