using setvalue() to update date field, not refreshing page
using setvalue() to update date field, not refreshing page
On editing a row, I want to update the date field value in my table IF a certain checkbox is checked, on my editor form, otherwise do nothing.
So i am checking for a post with action edit
My database table is being updated, but the datatable is not being refreshed.
I am using editor 1.4 beta
$filter = isset($_GET['DetailOrderID'])?$_GET['DetailOrderID']:1;
// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'tblorderdetails', 'DetailID' );//table name and PKey(defaults to ID)
if ( Editor::action( $_POST ) === Editor::ACTION_EDIT ) {
//retrieve values from editor
$returnvalue = $_POST['data']['tblorderdetails']['Returned'];
if ($returnvalue == 1) {
$editor->field(
Field::inst('tblorderdetails.ReturnedDate')
->setValue($today)
->getFormatter( 'Format::date_sql_to_format', 'd M Y' )
);
} else {
$editor->field(
Field::inst('tblorderdetails.ReturnedDate')
->set( Field::SET_NONE )
->getFormatter( 'Format::date_sql_to_format', 'd M Y' )
);
}
} else {
$editor->field(
Field::inst('tblorderdetails.ReturnedDate')
->set( Field::SET_NONE )
->getFormatter( 'Format::date_sql_to_format', 'd M Y' )
);
}
$editor->field(
Field::inst( 'tblorderdetails.DetailOrderID' ),
Field::inst( 'tblorderdetails.DetailProductID' ),
Field::inst( 'tblorderdetails.DetailName' ),
Field::inst( 'tblorderdetails.DetailPrice' ),
Field::inst( 'tblorderdetails.DetailSKU' ),
Field::inst( 'tblorderdetails.Returned' )
->setFormatter( function ( $val, $data, $opts ) {
return ! $val ? 0 : 1;
} )
)
->where('tblorderdetails.DetailOrderID', $filter);
$data = $editor
->process( $_POST )
->data();
http://test2.forthwebsolutions.com/plugins/shop/orders.php
to test, select an order, and in the order details table, click the return item link, if there is one
This question has an accepted answers - jump to answer
Answers
This might be a bug in the 1.4.0-beta.1 release. In the Field.php file there was a typo in the
public function val ( $direction, $data )
function. If you look just a couple of lines into the function you will see:It should be:
Allan
Alas, my Field.php was already updated (line 519) so I 'm guessing its something else.
I have used setvalue() successfully before with an anonymous function and a session value, maybe its the logic in my ajax json above ?
I don't see anything immediately wrong with it. I would suggest reformatting it to be simpler and defining the date field only once and then modifying it as needed through the API, but beyond that I think you would need to add debugging to make sure the
$returnvalue
and$today
are what you expect them to be:Allan
hmm,
i used the code snippet you supplied, and set the $returnvalue to 1 and the date to a string '2009-10-10'
The result is the same, the db is updated, but the datatable isn't, - until i do a refresh
This sure does sound like the bug in beta 1 with the [gs]etValue issue. Is it possible that the fixed file might not be getting used in this case?
What is the JSON return from the server on edit? Beyond that, I think I would need to actually debug the script directly - is that possible?
Allan
i have uploaded the latest test page here
http://test2.forthwebsolutions.com/plugins/shop/orders.php
I am happy to give you a pm and screenshare if it helps
The issue is in the lower table when you try to edit something? When I try it the row disappears as the server is returning
{ row: null }
on edit. Is that the issue?It does that because of the
where
condition being applied:There is no
DetailOrderID
GET parameter on that edit request, so the row isn't visible under the condition applied and thus the row gets removed from the client-side table.Allan
Thanks Allan, I just didn't see that.
So i passed the orderid as a post parameter from my form, and updated the filter parameter in the where condition if the editor form has been posted.
Sweet
Test page updated, and it works
Thanks very much for your help