tablename.dv.js DATA VALUE CATCH ??

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fdissait
Posts: 23
Joined: 2019-07-24 07:57

tablename.dv.js DATA VALUE CATCH ??

Post by fdissait » 2023-03-29 13:54

Hello AppGini team !
I try to write a control procedure on validating or updating a field. I try to use javascript on a dv.js file, using the example from udemy course N°9.
Unfortunately, I cannot catch the code_colis data. With console.log, it keeps the initial value of 10 ...
Can you help to pass a value from PHP to JS ? Thanks a lot for help !!
François.

batches.php (part)
/**
* Called before executing the insert query.
*
* @param $data
* An associative array where the keys are field names and the values are the field data values to be inserted into the new record.
* Note: if a field is set as read-only or hidden in detail view, it can't be modified through $data. You should use a direct SQL statement instead.
* For this table, the array items are:
* $data['code_colis'], $data['item'], $data['DLU'], $data['quantity'], $data['manufacturing_date'], $data['nombre_paquets'], $data['poids_colis'], $data['etat'], $data['peremption'], $data['en_cours']
* $data array is passed by reference so that modifications to it apply to the insert query.
* on recherche si l'item inséré est géré en poids unitaire , on récupère son poids et on le multiplie par la quantité pour avoir le poids dui colis ....
* @param $memberInfo
* An array containing logged member's info.
* @see https://bigprof.com/appgini/help/workin ... memberInfo
*
* @param $args
* An empty array that is passed by reference. It's currently not used but is reserved for future uses.
*
* @return
* A boolean TRUE to perform the insert operation, or FALSE to cancel it.
*/
global $inc;
global $erreur;
$erreur=0;
function batches_before_insert(&$data, $memberInfo, &$args)
{
/* recupere les valeurs des data */
$id_item = $data['item'];
$gestion_poids = sqlValue ("SELECT items.gestion_p_u FROM items where items.id = $id_item ");
$poids_unitaire = sqlValue("SELECT items.poids_unitaire from items where items.id = $id_item ");
$stock = sqlValue("SELECT items.balance from items where items.id = $id_item");
$section = sqlValue ("SELECT items.section FROM items where items.id = $id_item ");

/*MISE EN FORME NUMERO COLIS*/
$numero_colis = $data['code_colis'];

batches.dv.js :
var numero =10;

function show_error(field, msg){
modal_window({
message: '<div class="alert alert-danger">' + msg + '</div>',
title: 'Erreur dans ' + field,
close: function(){
$j('#' + field).focus();
$j('#' + field).parents('.form-group').addClass('has-error');
}
});

return false;
}

$j(function(){
$j('#update, #insert').click(function(){
/* Make sure freight, if provided, is between 0 and 500
here I try to catch the value of field code_colis */
var numero = $j('#code_colis').val();
console.log(numero);
/*Here I shall write the controle procedure when I have the value of numero */
if(isNaN(numero) || numero < 0 || numero > 500){
return show_error('code_colis', 'numero must be a number between 0 and 500.');
}
});
})

fdissait
Posts: 23
Joined: 2019-07-24 07:57

Re: tablename.dv.js DATA VALUE CATCH ??

Post by fdissait » 2023-05-08 07:34

This was solved with careful reading of examples .....

Post Reply