need to store pre edited value in a variable using preEdit problem
need to store pre edited value in a variable using preEdit problem
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi
I am using a copy of the parent child blog scripts as my template to test the preEdit function, as I need to store the value of a field before it is edited and assigned a new value, using Datatables Editor.
I have added users.quantity
and users.previous_quantity
and I have tried to write the content of ``users.quantityinto
users.previous_quantityusing the
preEditfunction, but the variable
$preEditQuantity = $values['users']['quantity'];``` is always assigned the post edited value.
server script
<?php
// DataTables PHP library
include( "../lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
if ( ! isset($_POST['site']) || ! is_numeric($_POST['site']) ) {
echo json_encode( [ "data" => [] ] );
}
else {
Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.first_name' ),
Field::inst( 'users.last_name' ),
Field::inst( 'users.phone' ),
Field::inst( 'users.site' )
->options( 'sites', 'id', 'name' )
->validator( 'Validate::dbValues' ),
Field::inst( 'sites.id' ),
Field::inst( 'sites.name' ),
Field::inst( 'users.previous_quantity' ),
Field::inst( 'users.quantity' )
)
->on( 'preEdit', function ( $editor, $id, $values ) {
$preEditQuantity = $values['users']['quantity'];
$editor
->field('users.previous_quantity')
->setValue($preEditQuantity);
})
->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
->where( 'site', $_POST['site'] )
->process($_POST)
->json();
}
after edit of Quantity
field from 3000 to 2000 I have echoed the value of the variable
$preEditQuantity
and it is displaying as 2000 the post Edited value.
I can provide access to my system for testing if required by sending a PM, with thanks.
any help much appreciated
thanks Colin
Replies
I have found a few examples of possible answers so hopefully I have a solution.
https://datatables.net/forums/discussion/35742/update-table-using-preedit-to-set-field-value
https://datatables.net/forums/discussion/62696/logging-preedit-values-on-postedit-with-multi-row-updates
Thanks Colin