Get data via AJAX when leaving the field

Get data via AJAX when leaving the field

KostasRKostasR Posts: 24Questions: 5Answers: 0

Hello all,

sorry i am new and inexperienced!

As an example, I would like to add articles in an invoice.

I have the fields item number, article name, quantity and price.
If I enter the article number and leave the field, I would like to retrieve the article name and the price from the database via AJAX and write it into the grid.
Is there an example for this?

I looked at all the examples and found no solution.

regards,
Kostas

This question has an accepted answers - jump to answer

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    Answer ✓

    You might resolve this with dependent https://editor.datatables.net/reference/api/dependent().

    Or you can do something like this:

    editor.on("open", function ( e, mode, action ) {
        $(editor.field("articleNr").node())
                .on("change", function() {
    
            var articleNr = editor.field("articleNr").val();
    
            if (articleNr > 0) {
                $.ajax( {
                    url: "Ajax//getArtilceDetails/" + articleNr,
                    dataType: "JSON",
                    success: function ( json ) {
                        editor.field("articleName").update(json);
                        editor.field("articlePrice").update(json);
                    }
                });
            }
        });
    });
    
  • KostasRKostasR Posts: 24Questions: 5Answers: 0

    Thank you for your support.
    Just what I was looking for.

This discussion has been closed.