0

Some how it becomes very complicated for me to achieve this.

// HERE WE WILL ARE CREATING THE ARRAY OF OBJECTS
let getAllAssetsData = [];
$('#productList tr').not(':first').each(function(index,value){
    let getPT = $(this).find('.dropdown').val();
    let getPm = $(this).find('.pm').val();
    let getSn = $(this).find('.sn').val();
    getAllAssetsData.push({
        'pt'  : getPT,
        'pm'  : getPm,
        'sn'  : getSn,
    });
});

// THIS IS WHAT I AM TRYING
$(getAllAssetsData).each(function(index1,value1){
    $(getAllAssetsData).each(function(index2,value2){

        // HERE I NEED TO COMPARE ALL ARRAY VALUES TO EACH OTHER AND MAKE DUPLICATE VALIDATION
        if((value1.pt === value2.pt) && (value1.pm === value2.pm) && (value1.sn === value2.sn)){

            // HERE DUPLICATE ELEMENT FOUND 

            console.log(value1.pt);
            console.log(value2.pt);

            console.log(value1.pm);
            console.log(value2.pm);

            console.log(value1.sn);
            console.log(value2.sn);

            alert('asd');

        }
    });
});

On Click on add button it is very easier for me to only add unique set of values, but if user have rights to change values after adding into the list, so how do i check duplication on click of "NEXT" button ?

enter image description here

Vipertecpro
  • 3,056
  • 2
  • 24
  • 43
  • 1
    If you want to compare the values of `value1` and `value2` I suggest checking out [Object comparison in JavaScript](https://stackoverflow.com/questions/1068834/object-comparison-in-javascript) – 3limin4t0r Jan 18 '21 at 16:07
  • @3limin4t0r is my logic correct ? – Vipertecpro Jan 18 '21 at 16:27
  • Can you add a fragment of your **productList**? It should not hard to solve your issue adding an input event handler for text box and change for select...... – gaetanoM Jan 18 '21 at 16:32
  • Instead of && use || because here any field can be duplicate . – Swati Jan 18 '21 at 16:51
  • @Swati That depends on the context. If you want each field to hold a unique value per column then you should use `||`, if you want the combination of fields to be unique you should use `&&`. – 3limin4t0r Jan 18 '21 at 17:02
  • @Swati That's right i need each row to be unique while adding into the product list, that is why using && – Vipertecpro Jan 18 '21 at 17:44
  • @gaetanoM That i cannot do, user can change anything anytime, but it should be unique before going to the next wizard form, putting handler on each input and select (while adding dynamic rows ), that's gonna be messy, that why i simply want to make alert popup which says "Please check duplicate entry". 'fragment of your productList' ?? i attached screenshot of the productList – Vipertecpro Jan 18 '21 at 17:47

0 Answers0