<script>
	document.addEventListener('focusin',(event) => {
		var target = event.target;
		if (!(target instanceof HTMLElement) ) {
			return;
		}

		if (!$(event.target).data('updatevalue')) {
			return;
		}

		$(target).data('oldvalue', $(target).val());

		/*if ($(event.target).hasClass('zoom')) {
			$(target).select();
		}*/
	});

	document.addEventListener('change',(event) => {
		var target = event.target;
		if (!(target instanceof HTMLElement) ) {
			return;
		}

		if (!target.hasAttribute('data-updatevalue')){
			return;
		} 

		var fieldName = $(target).attr('name');

		if ($(target).attr('type') == 'checkbox') {
			var value = $(target).is(':checked');
		} else {
			var value = $(target).val();
		}

		activeLoader();
		$.ajax({
			dataType: 'json',
			url: '{{ path('Catalogue.parametrageFormat.updateValue', {IdFormat : idFormat}) }}',
			data: {'field' : fieldName, 'value' : value},
			type: "POST",
			success: function(content){
				if (content.statut == 'O') {
					
					refreshFonction('arianeSub', content.ariane);
					desactiveLoader();

				} else {
					desactiveLoader();
					$(target).val($(target).data('oldvalue'));

					$("#modal-content").addClass("modal_small");
					$("#modal-body").html(content.content);
					$("#modal-title").html(content.title);

					activePopup();
				}
			}
		});
	});
</script>