mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-22 20:51:47 +00:00
33 lines
898 B
JavaScript
33 lines
898 B
JavaScript
![]() |
// XXX Esto solo está acá para cumplicar con objetivos de
|
||
|
// documentalmexicano.org
|
||
|
|
||
|
$(document).on('turbolinks:load', function() {
|
||
|
var porcentajes = $('[id^=post_porcentaje_de_financiacion_]');
|
||
|
|
||
|
porcentajes.on('change', function() {
|
||
|
// Obtener todos los valores
|
||
|
var values = porcentajes.map(function(i, e) {
|
||
|
return (e.value.length > 0) ? parseInt(e.value) : 0;
|
||
|
}).toArray();
|
||
|
|
||
|
// Obtener la suma de los valores
|
||
|
var sum = values.reduce(function(i, e) {
|
||
|
return i + e;
|
||
|
}, 0);
|
||
|
|
||
|
// Si superan el 100%, estan mal
|
||
|
if (sum > 100) {
|
||
|
porcentajes.addClass('is-invalid');
|
||
|
} else {
|
||
|
porcentajes.removeClass('is-invalid');
|
||
|
}
|
||
|
|
||
|
var max = 100;
|
||
|
porcentajes.each(function(i, porcentaje) {
|
||
|
$(porcentaje).attr('max', max);
|
||
|
$(porcentaje).parent().find('.input-max').text(max);
|
||
|
max = max - porcentaje.value;
|
||
|
});
|
||
|
});
|
||
|
});
|