demarches-normaliennes/app/javascript/new_design/champs/siret.js

36 lines
853 B
JavaScript
Raw Normal View History

2018-08-09 11:53:59 +02:00
import $ from 'jquery';
2018-08-16 18:04:18 +02:00
$(document).on('input', '[data-siret]', evt => {
const input = $(evt.target);
const value = input.val();
const url = input.data('siret');
2018-08-16 18:04:18 +02:00
switch (value.length) {
case 0:
input.removeData('invalid');
$.get(url, { siret: 'blank' });
break;
case 14:
input.attr('disabled', true);
$('.spinner').show();
$.get(url, { siret: value }).then(
() => {
input.removeData('invalid');
input.removeAttr('disabled');
$('.spinner').hide();
},
() => {
input.removeAttr('disabled');
input.data('invalid', true);
$('.spinner').hide();
}
2018-08-16 18:04:18 +02:00
);
break;
default:
if (!input.data('invalid')) {
input.data('invalid', true);
$.get(url, { siret: 'invalid' });
}
}
});