Hi,
I am trying to implement a collection which has only one field with unique values. If it is repeated field turn red.
So far it works well when adding a new field
$('.cf-collection-block').on('blur','input',function(){ var current_value = $(this).val(); var repeated= false; $('.cf-collection-block ul').each(function(index){ var size= $('.cf-collection-block ul').size(); if ( (current_value == $(this).find('#q14 input').val()) && (size > 1) && ( index!= size-1 )) { repeated = true; } else { } }); // for each if (repeated == true) { repeated = false; current_index=0; this.setAttribute('style', 'background-color: rgb(255,224,224) !important'); } });
Size>1 makes sure that first value doesn't compare itself and index = size -1 is for last value which was just added.
Problem is when i click /edit any value that is unique but was added earlier (already there) it turns red even though it is unique.
I believe inside for each loop it compares itself which is a problem.
Any solution?
Thanks in advance.
Junaid Inam