demarches-normaliennes/app/assets/javascripts/new_design/champs/siret.js

31 lines
848 B
JavaScript
Raw Normal View History

2018-04-03 17:53:14 +02:00
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');
2018-04-09 18:27:15 +02:00
$('.spinner').show();
2018-04-03 17:53:14 +02:00
$.get(url+'?siret='+value).then(function() {
input.removeAttr('data-invalid');
input.removeAttr('disabled');
2018-04-09 18:27:15 +02:00
$('.spinner').hide();
2018-04-03 17:53:14 +02:00
}, function() {
input.removeAttr('disabled');
input.attr('data-invalid', true);
2018-04-09 18:27:15 +02:00
$('.spinner').hide();
2018-04-03 17:53:14 +02:00
});
break;
default:
if (!input.attr('data-invalid')) {
input.attr('data-invalid', true);
$.get(url+'?siret=invalid');
}
}
});
});