using editor field value as an external variable in a select

using editor field value as an external variable in a select

crush123crush123 Posts: 417Questions: 126Answers: 18

i am setting up a returns form whereby i want to ensure the select field will have a maximum value of the original order quantity.

using the example on page https://editor.datatables.net/manual/php/joins#Options as a starting point

Field::inst( 'users.site' )
->options( Options::inst()
    ->table( 'sites' )
    ->value( 'id' )
    ->label( 'name' )
    ->where( function ($q) {
        $q->where( 'name', 'L%', 'LIKE' );
    }
);

instead of the Like L%, I want to set my 'where' parameter using the value from a different editor field value, tblorderdetails.Quantity

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I think the problem you might run into there is that for each row the maximum value might be different. That might or might not be true in your data set, but it sounds like something that might be specific to the row that is being edited.

    If that is the case you would need to use initEdit to get the information from the server based on the row being edited and populate the options.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    yes, that makes sense.

    so, basically, i retrieve the value originally ordered from my editor instance and use this as a parameter ?

    this is what I have done, and it seems to work...

             //set the values in the select field to have a maximum value of that originally ordered
         var saleqty = editor.field('tblorderdetails.DetailQuantity').val()
    
                $.ajax ({
                  url: '/ajax/ajax_selectreturnqty.php',
                  data: {saleqty: saleqty},
                  dataType: 'json',
                  success: function (json) {
                  editor.field('tblorderdetails.ReturnedQty').update( json.refqtysold );
                  }
              })
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That looks spot on to me - nice one!

    Allan

This discussion has been closed.