Get Data from AutoComplete Field

Get Data from AutoComplete Field

raspoteenraspoteen Posts: 16Questions: 8Answers: 0
edited October 2017 in Free community support

Hi, please look at the image in the attachments, the first field is AutoComplete field (source is the database), and I want to fill the other fields from the selected item from AutoComplete field, so when the user click on the (products1 as example) the other fields should be filled with products1 details like price, QTY .. etc
is that possible in the DataTables ? and How?

var editor; // use a global for the submit and return data rendering in the examples
        $(document).ready(function () {
            editor = new $.fn.dataTable.Editor({
                ajax: {
                    url: 'cart_getter',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                },
                table: "#table_id",
                idSrc: "id",
                fields: [{
                    label: "Search Products:",
                    name: "search",
                    type: "autoComplete",
                    opts: {
                        source: 'http://127.0.0.1:8000/search',
                    }
                }, {
                    label: "Product Name:",
                    name: "product_name",
                }, {
                    label: "Quantity:",
                    name: "quantity"
                }, {
                    label: "Buy Price:",
                    name: "buy_price",
                    type: "readonly",
                }, {
                    label: "Buy Currency:",
                    name: "buy_currency",
                    type: 'readonly',
                    options: [{label: "Dollar ($)", value: "1"}, {label: "Iraqi Dinar (IQD)", value: "0"}]
                }, {
                    label: "Sell Price:",
                    name: "sell_price"
                }, {
                    label: "Sell Currency:",
                    name: "sell_currency",
                    type: 'select',
                    options: [{label: "Dollar ($)", value: "1"}, {label: "Iraqi Dinar (IQD)", value: "0"}]
                },

                ]
            });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin
    Answer ✓

    Absolutely possible. There are a few ways of doing it - the easiest would be to use dependent() to make the Ajax request and have it fill in the values.

    Or you could use Select2 / Selectize (plug-ins of which are available for Editor) to show a list of options as the user is typing in the search. Then when they select an entry use the change event and val() to set the field values.

    Allan

This discussion has been closed.