[SOLVED] Call to undefined method <form>_apl::ajax_return_values_<field>() on AJAX onChange event

I need some help with AJAX events. The real problem at the moment is an exception is being raised for a call to an undefined function () on an onChange AJAX event. A side issue might be that I am not entirely sure how the parameters work for these events in Scriptcase - the usual help/tutorials etc. seem to bypass these details.

Background - (this is a bit of a contrived example - but you’ll get the gist of it) - Part of a self-registration form has two fields - nameGiven and namePreferred. When the first field changes I want to update the second with the value of the first, if it is not already set by the user with a preferred name value. Both these fields are defined in MySQL as varchar(40).

Implementation - Originally I performed this task using a JS onChange function, but I want to add some more capability (beyond the contrived example) that makes JS impractical. So I have deleted the JS onChange function and added an AJAX onChange event, which simply executes one line (at the moment):

if ( (strlen({namePreferred})) ) {namePreferred} = {nameGiven);

While I am not 100% sure what I am doing with the parameters, I have double-clicked on nameGiven and namePreferred to mark them as parameters.

Execution / Error - Code is then generated and the form is run. I set the nameGiven value and hit tab… and boom!… Fatal error/Uncaught Error - call to undefined method <form_name>_apl::ajax_return_values_namepreferred()

What normally causes this kind of problem? Any ideas where I could be going wrong?

I am using SC V9.7.10

Thanks in advance.

Cheers, Russell.

SOLVED (But, IMO, a BUG…).

First I need to elaborate on the above example - it was a bit contrived (over simplified). What is actually happening is that there were three text fields. Let’s call them {text1}, {text2} and {text3}. All three are stored in the same DB table, but {text3} is a concatenation of {text1} and {text2} plus some addition text - the nature of the latter part requires some interpretation of {text1} and {text2}. Also, {text3} does not need to be visible to the user on this form, and as such, the {text3} appears on the Fields Not Shown section of the page in the Edit Fields section.

As per my problem description (above), if either {text1} or {text2} changes, then {text3} needs to be updated and stored along with the other two (updated) fields. As outlined, I set up AJAX onChange events for {text1} and {text2}, which passes {text3} as a parameter and updates the latter concatenated field - the idea being that when the record is saved, the modified {text3} will also be saved. However, when the AJAX onChange event fires, you get the Fatal Error - Call to undefined method.

If I simply move {text3} from the Fields Not Shown section of the page to a visible block in the page, and re-gen/re-run, then the onChange event works - no error. Yep! That’s right.

Conclusion - It would appear that, at least in v9.7.10, Scriptcase fails to generate the ajax_return_values_() method for fields in the Fields Not Shown section of the page, whether or not you specify that field as a parameter to the AJAX event or not. (see also my “one last thing” para at the end).

Workaround - Move the field which you do not wish to show to the user (but which you might still use/update in other forms) to a visible block within the page and use the sc_field_display() macro to hide the field inside the form onLoad event.

Hopefully this helps you save a bit of debug time if you receive the same error.

And One last thing - I still cannot work out the purpose of the Parameters section (Tab) in the AJAX Events definition of the form. I simply cannot work out whether it makes any difference or not, or what happens if you do not define any parameters. The tutorials make no mention of any of it. Is this just defunct, or can someone please explain the purpose of it?