Skip to content

Instantly share code, notes, and snippets.

@cupertinobr
Last active December 16, 2022 19:56
Show Gist options
  • Save cupertinobr/5ae1dd4b2cef1a265f17825cd8819853 to your computer and use it in GitHub Desktop.
Save cupertinobr/5ae1dd4b2cef1a265f17825cd8819853 to your computer and use it in GitHub Desktop.
Enviar seleção de dados para um Select2
<?php
public static function onChangeProduto($param = null)
{
try
{
//code here
if(!empty($param['key']))
{
//code here
TTransaction::open(self::$database);
$objeto = Produto::find( $param['key'] );
$field_id = explode('_', $param['_field_id']);
$field_id = end($field_id);
$location_id = $param['location_id'];
$product_uom_id = $objeto->uom_id;
$object = new stdClass();
$object->{"product_uom_id_{$field_id}"} = $product_uom_id;
// JS to update tfiledlist select2 uom_id
TScript::create( "$('#product_uom_id_{$field_id}').val('{$product_uom_id}');" );
TScript::create( "$('#product_uom_id_{$field_id}').trigger('change')" );
//get main location_id and set on Select2
$object->{"location_id_{$field_id}"} = $location_id;
// JS to update tfiledlist select2 location_id
TScript::create( "$('#location_id_{$field_id}').val('{$location_id}');" );
TScript::create( "$('#location_id_{$field_id}').trigger('change')" );
TForm::sendData(self::$formName, $object);
TTransaction::close(); // close the transaction
}
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment