Forum OpenACS Development: Re: Forms X matrix input structure

Collapse
Posted by Iuri Sampaio on
Dave,

What do you mean by "don't use onChange" javascript event?
How would I load up the other fields then?

For example, let's supose the user selects field1.0.
The form must be refreshed and the fields must be automatically filled. "Every row respectively"

field2.0 field3.0 field4.0 field5.0

I agree their patterns are very much the same. I would rather to go with plain javascript. That way I get a cleaner mix with TCL, becasue I wouldn't be using any other libraries with xml and json data structures.

The hard part, that I am stuck at, is to load the fields into the html inputs. Mainly how to pass the data between javascript and TCL, and what structure to use.

I guess i have the knowledge about the pieces, however I still don't have a picture of "how" to accomplish the task.

Collapse
Posted by Ryan Gallimore on
Build your datasource in Tcl as usual, then output the results to your ADP as Javascript.

To send data from your form to the db (without refreshing), execute an AJAX request with your favourite library to a Tcl file that saves the data to the db.

Don't use "onChange", instead use an Event Listener (google addEventListener).

Hope that helps.

Collapse
Posted by Iuri Sampaio on
Ryan and Dave,
Thank you guys for the feedback.
It helped a lot. I don't know how but it works! (sharing and writting about difficulties surprisingly open the mind. It makes you to look outsite the box.

It turned out I wrote the datasource on TCL and a json structure to move the data here and there, between the javascript and TCL structures.

I saw openacs lacks json interfaces. Its API is very poor. Isn't?

Am I correct?

Collapse
Posted by Torben Brosten on
Iuri,

You might be interested in the qf_ form API. It's made for scenarios like the one you have, with multiple arrays, dynamically declared forms and fields etc:

https://openacs.org/forums/message-view?message_id=3602056

It doesn't include javascript, but it's easily added.

cheers,

Torben