Accessing watch value in CDD

pastvne

Bruce Decker
I have a CDD that watches a form element {table1___choice}

I want to use the current value in the form within eval code within the CDD advanced tab. However, I am having a difficult time accessing the value. It seems to always return the value that was loaded at the time the record was edited, not the current selected value:

I've tried:

$value = '{table1___choice}'
$value = $data['table1___choice']

and I've tried $formData and even the getElement method from the jFACTORY class.

I can get a calc element to properly return the value but I can't seem to reference the calc element's value.

So, what is the best way within a CDD eval php to reference the current selected value of it's watch element (or any current form value for that matter).

Thanks,
Bruce
 
Hi All, I've been looking through the source for the CDD and the Calc plugin looking to see if the the calc value of a calc element is passed to the back-end PHP and stored in a variable that I can access from my CDD. If anyone can give me a hint or a better way to be able to access the changed value of a watched element (on the form) within the EVAL() of a CDD, that would allow me to do what I need to do. If I've not provided a clear enough explanation of the issue, please let me know.
 
The current state of the form data should be in $data, along with the other args passed by the AJAX call ... so the watched element value should be $data['v'], as well as it's full element name.

What are you seeing / not seeing in $data?

-- hugh
 
Thanks Hugh. I have been looking through $data by using the $opt->text on the CDD and poking values from $data into it via the eval code. If the CDD eval code indeed executes based on the watch value change (which it appears to do), I'll setup a trace where a var_dump the $data array to a file and capture that as I change the watch value. That might clue me into what I'm doing wrong. The tip of $data['v'] I will try first and I'll report back what I find with an example for the wiki.
 
Hi Hugh:
It turns out that the value was in $data but I was not referencing it correctly. My watch value was a database joint rendered as a dropdown. The name of the element was fd_entity_credentials___entity_id.

It appears that this element of $data contains an array, not the (int) id I was looking for so I had to change this PHP reference:

Code:
$entityId = (int) $data['fd_entity_credentials___entity_id_raw'];
To this:
Code:
$entityId = (int) $data['fd_entity_credentials___entity_id_raw'][0];

It must have been confusing the CDD that I was referencing an array as an int and so that was preventing my code from picking up the value I expected. Not sure if this warrants a note in Wiki but I'll think about whether this is too obscure to mention (or too difficult to explain).

But thanks for pointing me to the north star... once again my friend!

Fabrik rocks!
 
Well, joins - and indeed anything based the 'elementlist' model which has the concept of multiple values, like dropdowns, radios, joins, etc - will always be an array in the submitted form data. Even if they are set to a single select type (dropdown as opposed to multiselect, say). That's how HTML submits the form data for those form input types.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top