Editor: How to pass select label to update method?

Editor: How to pass select label to update method?

joakim-mjoakim-m Posts: 5Questions: 3Answers: 0
edited April 2015 in Free community support

In my Persons table I have a column like this

"columns": [
    { "data": "compName" },

and this field in Editor

fields: [
    {
        label: 'Company',
        name: 'compID',
        type: 'select',
        optionsPair: {
            label: 'compName',
            value: 'compID'
        }
    },

The select field is populated thus:

$.getJSON("companies.json", function (data) {
    editor.field('compID').update(data);
});

When editor sends ajax it wants new row data in return.

My updatePerson() method already knows the compID (passed as data[compID]).
Can the newly selected compName be passed the same way?

This question has an accepted answers - jump to answer

Answers

  • joakim-mjoakim-m Posts: 5Questions: 3Answers: 0
    edited April 2015

    Got it:

    editor.on("preSubmit", function (event, data, action) {
        var cn = editor.field('compID').s.opts._input[0].selectedOptions[0].label;
        data.data.compName = cn;
    });
    

    However, this is not the proper way to do joins. Here's the manual entry on Join tables - working with multiple SQL tables

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    You could use the public API with a bit of jQuery to do it:

    editor.on("preSubmit", function (event, data, action) {
        var cn = editor.field('compID').input().find('option:selected').text();
        data.data.compName = cn;
    });
    

    Using field().input().

    Allan

This discussion has been closed.