Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Dynamicaly enable disable an object in a form

Questions related to using nuBuilder Forte.
Locked
gniko
Posts: 8
Joined: Mon Mar 12, 2018 7:42 am

Dynamicaly enable disable an object in a form

Unread post 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.
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Dynamicaly enable disable an object in a form

Unread post 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
gniko
Posts: 8
Joined: Mon Mar 12, 2018 7:42 am

Re: Dynamicaly enable disable an object in a form

Unread post by gniko »

Thanks Steven,
That did the trick.
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Dynamicaly enable disable an object in a form

Unread post by admin »

.
Locked