Update calculator min RAM input js validation

This commit is contained in:
PCoder 2018-10-16 08:58:12 +02:00
parent 26970ece92
commit b7cc7b08ce

View file

@ -44,6 +44,7 @@
_initNavUrl(); _initNavUrl();
_initPricing(); _initPricing();
ajaxForms(); ajaxForms();
$('#ramValue').data('old-value', $('#ramValue').val());
}); });
$(window).resize(function() { $(window).resize(function() {
@ -148,29 +149,65 @@
var data = $(this).data('minus'); var data = $(this).data('minus');
if (cardPricing[data].value > cardPricing[data].min) { if (cardPricing[data].value > cardPricing[data].min) {
if(data === 'ram' && cardPricing[data].value === 1){ if(data === 'ram' && String(cardPricing[data].value) === "1" && minRam === 0.5){
cardPricing[data].value = 0.5; cardPricing[data].value = 0.5;
$('#ramValue').val('0.5');
$("#ramValue").attr('step', 0.5);
} else { } else {
cardPricing[data].value = Number(cardPricing[data].value) - cardPricing[data].interval; cardPricing[data].value = Number(cardPricing[data].value) - cardPricing[data].interval;
} }
} }
_fetchPricing(); _fetchPricing();
$('#ramValue').data('old-value', $('#ramValue').val());
}); });
$('.fa-plus-circle.right').click(function(event) { $('.fa-plus-circle.right').click(function(event) {
var data = $(this).data('plus'); var data = $(this).data('plus');
if (cardPricing[data].value < cardPricing[data].max) { if (cardPricing[data].value < cardPricing[data].max) {
if(data === 'ram' && cardPricing[data].value === 0.5){ if(data === 'ram' && String(cardPricing[data].value) === "0.5" && minRam === 0.5){
cardPricing[data].value = 1; cardPricing[data].value = 1;
$('#ramValue').val('1');
$("#ramValue").attr('step', 1);
} else { } else {
cardPricing[data].value = Number(cardPricing[data].value) + cardPricing[data].interval; cardPricing[data].value = Number(cardPricing[data].value) + cardPricing[data].interval;
} }
} }
_fetchPricing(); _fetchPricing();
$('#ramValue').data('old-value', $('#ramValue').val());
}); });
$('.input-price').change(function() { $('.input-price').change(function() {
var data = $(this).attr("name"); var data = $(this).attr("name");
cardPricing[data].value = $('input[name=' + data + ']').val(); var input = $('input[name=' + data + ']');
var inputValue = input.val();
console.log(".input-price change " + data + " => " + inputValue);
if(data === 'ram' && window.minRam === 0.5) {
if (inputValue === '1'){
//$('input[name=' + data + ']').attr('step', 0.5);
}
}
if(data === 'ram') {
var ramInput = $('#ramValue');
if ($('#ramValue').data('old-value') < $('#ramValue').val()) {
console.log("$('#ramValue').val() = " + $('#ramValue').val() + ", and minRam = " + minRam);
if($('#ramValue').val() === '1' && minRam === 0.5) {
console.log("Setting step = 1");
$("#ramValue").attr('step', 1);
$('#ramValue').val('1');
}
console.log('Alert up');
} else {
if($('#ramValue').val() === '0' && minRam === 0.5) {
console.log("Setting step = 0.5");
$("#ramValue").attr('step', 0.5);
$('#ramValue').val('0.5');
}
console.log('Alert down');
}
inputValue = $('#ramValue').val();
$('#ramValue').data('old-value', $('#ramValue').val());
}
cardPricing[data].value = inputValue;
_fetchPricing(); _fetchPricing();
}); });
} }