• Resolved uafinsee

    (@uafinsee)


    Hi.

    I have a calculator where users enter loan amount and time and see how much they will pay in 25 credit companies.

    In order to sort results from lowest to highest I`ve inserted hidden calculated field with the following code:

    (function myfun() {
    var list = {};

    list[fieldname17] = jQuery(‘.cont02’);
    list[fieldname27] = jQuery(‘.cont03’);
    list[fieldname35] = jQuery(‘.cont04’);
    list[fieldname41] = jQuery(‘.cont05’);
    list[fieldname49] = jQuery(‘.cont06’);
    list[fieldname58] = jQuery(‘.cont07’);
    list[fieldname72] = jQuery(‘.cont08’);
    list[fieldname81] = jQuery(‘.cont09’);
    list[fieldname90] = jQuery(‘.cont10’);
    list[fieldname99] = jQuery(‘.cont11’);
    list[fieldname108] = jQuery(‘.cont12’);
    list[fieldname114] = jQuery(‘.cont13’);
    list[fieldname120] = jQuery(‘.cont14’);
    list[fieldname129] = jQuery(‘.cont15’);
    list[fieldname138] = jQuery(‘.cont16’);
    list[fieldname147] = jQuery(‘.cont17’);
    list[fieldname155] = jQuery(‘.cont18’);
    list[fieldname165] = jQuery(‘.cont19’);
    list[fieldname170] = jQuery(‘.cont20’);
    list[fieldname179] = jQuery(‘.cont21’);
    list[fieldname188] = jQuery(‘.cont22’);
    list[fieldname194] = jQuery(‘.cont23’);
    list[fieldname203] = jQuery(‘.cont24’);
    list[fieldname212] = jQuery(‘.cont25’);
    var keys = Object.keys(list);
    keys.sort(function (a, b) { return b – a });

    var tmp;
    for (var i = 0; i < keys.length; i++) {
    if(typeof tmp == ‘undefined’)
    {
    tmp = i; continue;
    }
    list[keys[tmp]].before( list[keys[i]]);
    delete list[keys[tmp]];
    tmp = i;
    }
    return keys;
    })()

    “return keys” has been inserted only to identify the problem.
    And the first credit company is not inserted deliberately in order to be showed first.

    The problem is that this code works fine only until I show no more than 13 companies.

    If the user is able to obtain loan from 14 companies or more – the last 13 are showed correctly, the first ones – randomly.

    “return keys” shows that variable keys stores no more than 14 values (one of them “0”).

    What puzzles me is that I have a similar calculator and there similar code works completely fine.

    Could you please point me into direction why it doesn`t work with more than 13 companies here?

    the page is https://finsee.com/test/

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @uafinsee,

    The error is very simple, all calculated fields with the same result provokes that the corresponding index in the list be replaced with the last field, for example, in the following piece of code:

    list[fieldname17] = jQuery('.cont02');
    list[fieldname27] = jQuery('.cont03');
    list[fieldname35] = jQuery('.cont04');

    If the value of the fieldname17 field is equal to the values of fields fieldname27 and fieldname35, for example, 10, the piece of code would be:

    list[10] = jQuery('.cont02');
    list[10] = jQuery('.cont03');
    list[10] = jQuery('.cont04');

    So, list[10] would be simply: jQuery('.cont04')

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Mistakes in sorting of results’ is closed to new replies.