Update editor 1.3.1->1.5.2, editor.set fail

Update editor 1.3.1->1.5.2, editor.set fail

piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1

Hello, we've updated from above version of editor, and datatables to 1.10.10, and now a few editor.set doesn't work.

Two editor.set are next to each other, one works to one form field, while the other doesn't work. We're wondering if there's something different in how the table writing php file works, because it worked in 1.3.1, but doesn't now.

File that is in error: Datatables.editor.min.js
The error we get is 'TypeError: b is undefined', and it references line 18, col 317, and points to b.length. The word 'multiValues' is right before the b.length reference.

In testing, we've tried many variations to eliminate possibilities, and the problem drills down to it's the form field name, as we can replace all other parts, and it works Ok.

Thanks for any help you can provide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Hi,

    Could you show me how you are calling the set() method? Are you chaining it, using objects for the values, or anything else?

    Thanks,
    Allan

  • piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1
            $('select', editor.node('orders.id_customer_location_part')).on('change', function () {
            var res=getInternalPartNumberToMatch( editor, editor.get('orders.id_customer_location_part') )
            editor.set('part_master.part_number', res[0].value);
            editor.set('orders.id_part', res[0].label);
            } );
    

    these two above make the fail i referred to. the res.value and res.label come back correctly. This above snippet is after the editor section in the JS file.

    This section happens right after the above snippet:

        editor.on( 'open', function (e, type) {
            editor.set('orders.id_user_edit', id_user);
        } );
    

    and this works correctly.

    The top part works correctly in 1.3.1 of editor, using datatables 1.10.0. After moving to 1.5.2 and 1.10.10, it gives the error i listed.

    I'm thinking it's pointing to table writes, or something similar, as I can move the second editor.set up to the 'select' section, and it works OK. So it must be fields related me thinks.

  • piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1

    We've found an issue that explains the problem above. Below is your 'Field Types' example, which we loaded locally, and changed. Note that we put an event listener on the 'priority' select and had it act on the 'item' field, which we moved below the field that we put the event listener on. This worked OK for us in 1.3.1 editor, but now breaks in 1.5.2.

    If you uncomment the upper 'item' field and comment the bottom 'item' field, it works OK.

    $(document).ready(function() {
      editor = new $.fn.dataTable.Editor( { 
        ajax: "../php/todo.php",
        table: "#example",
        fields: [ /*{
          label: "Item:", 
          name:  "item"
        },*/ {
          label: "Status:",
          name:  "done",
          type:  "radio",
          options: [
            { label: "To do", value: 0 },
            { label: "Done",  value: 1 }
          ],
          "default": 0
        }, {
          label: "Priority:",
          name:  "priority",
          type:  "select",
          options: [
            { label: "1 (highest)", value: "1" },
            { label: "2",           value: "2" },
            { label: "3",           value: "3" },
            { label: "4",           value: "4" }, 
            { label: "5 (lowest)",  value: "5" }
          ]
        },
        {
           label: "Item:",
           name:  "item"
        }
      ]
    } );
    
    $('select', editor.node('priority')).on('change', function () {
        editor.set('item', 'Preset the Item');
    } ); 
    
  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Hi,

    Thanks for letting me know about this - I've just committed a fix that will stop the Javascript error from occurring - however, Editor now fires a synchronous change event when setting the value of the select input. The result is that your set value is written immediately, but then subsequently overwritten when Editor sets the value for the field (it sets the field values sequentially, which is why the field order matters as you noted above).

    I'm looking into how best address this and will post back when I've investigated further.

    Regards,
    Allan

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Hi,

    I've just committed a change to Editor that will address this in the 1.5.4 release which I currently plan for this coming Friday (4th Dec 2015).

    The change events are now asynchronous to allow the field values to all be set from the DataTable data, and then the change event handler can set the values as required.

    Regards,
    Allan

  • piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1

    Thanks much. We will incorporate 1.5.4 when it's out.

This discussion has been closed.