Reputation: 61
i have a problem with keyup function
I have a ordering form, wich has x ammount of items, some of them a grouped like:
Item 1 - Group1 Item 2 - Group1
Items who are grouped, have 2 input fields, 1 hidden and 1 visible, what i`m tryng to do, is to change the value of hidden input to the same value of visible input.
My problem is that the value changes only then, when input is no more focused, is there any way to do, that when value changes in focused input, it changes instantly?
Heres how i`m doing it:
$('.item .quantity').on("change paste keyup", function(event) {
var crr_item = $(this).parents(".item"),
quantity = $(this).val(),
items = crr_item.parent().children(".item"),
group = false;
if(crr_item.hasClass('group1'))
group = 'group1';
else if(crr_item.hasClass('group2'))
group = 'group2';
if(crr_item.hasClass('group1_hover'))
group = 'group1';
else if(crr_item.hasClass('group2_hover'))
group = 'group2';
for(var i = items.index(crr_item)-1; i >= 0; i--) {
var item = items.eq(i);
if(!item.hasClass(group)) break;
item.find('.quantity').val(quantity);
calc_sum_eu(item);
}
calc_sum_eu(crr_item);
for(var i = items.index(crr_item); i < items.length; i++) {
var item = items.eq(i);
if(!item.hasClass(group)) break;
item.find('.quantity').val(quantity);
calc_sum_eu(item);
}
});
Upvotes: 0
Views: 179
Reputation: 1800
try adding a flag on it that will check if it is focused or not
var isFocused = false;
$('.item .quantity').on("focus", function(event) {
isFocused = true;
});
$('.item .quantity').on("blur", function(event) {
isFocused = false;
});
then just add the isFocused variable in your keyup event to validate.
Upvotes: 1