Page 1 of 1

Dynamicaly enable disable an object in a form

Posted: Thu Oct 18, 2018 3:29 pm
by gniko
I have a form that includes a lookup table. I try to enable/disable another field of the form depending on the user selection.
To do it, I tried the following PHP code in the AB (AfterBrowse) PHP of the lookup value:

Code: Select all

// Get the object type id
$recid = nuLookupRecord()->ID;
$s = "SELECT * FROM category WHERE category_id = '{$recid}'";
$t  = nuRunQuery($s);
$r  = db_fetch_object($t);
//nuDebug($r->category_countable);
if ($r->category_countable==1){
   nuAddJavascript ("nuEnable('device_count');");
}else{
    nuAddJavascript("nuDisable('device_count');");
}
'device_count' is the name of the field to be enabled disabled
nuEnable('device_count');
and
nuDisable('device_count');
work as expected when used in the LUJS but not when called from the PHP code.

Re: Dynamicaly enable disable an object in a form

Posted: Thu Oct 18, 2018 10:32 pm
by admin
gniko,

nuAddJavascript won't have any effect only in Before Browse and Before Edit.

After Browse is for automating populating fields on an Edit Form.

I would suggest you update another - maybe hidden field.

eg.
After Browse (AB)

Code: Select all

$recid = nuLookupRecord()->ID;
$s = "SELECT * FROM category WHERE category_id = '{$recid}'";
$t  = nuRunQuery($s);
$r  = db_fetch_object($t);

nuSetFormValue('hidden_value', $r->category_countable);

Javascript (JSLU)

Code: Select all

if ($('#hidden_value').val() == 1){
   nuEnable('device_count');
}else{
    nuDisable('device_count');
}

Steven

Re: Dynamicaly enable disable an object in a form

Posted: Thu Oct 18, 2018 10:55 pm
by gniko
Thanks Steven,
That did the trick.

Re: Dynamicaly enable disable an object in a form

Posted: Thu Oct 18, 2018 11:14 pm
by admin
.