Forum OpenACS Development: export_vars and (form)vars containing colons

Hi,

I am almost done with the spellchecking gadget for ad_form that I've been working on. I should be able to come up with a number of patches quite soon and perhaps one of the gatekeepers could look at them and see if it something we'd like to add to the toolkit?

The new spellchecker will be fully templatable and supports checking of multiple input fields in one go. Those are the main features that the old one (3.x) didn't have...

There is one thing I'll need to fix first, though, and I think it has to do with export_vars, or improper use of it. The way I have implemented this, ad_form sends the form data to the spellchecker button by doing:

ad_return_exception_template -status 200 -params $args $spellcheck_template

Then, in the spellchecking template, I have this:

set entire_form [export_vars -form -entire_form -override { {merge_p 1} } info_vars]

The actual problem is that export_vars doesn't seem to handle vars that have a colon (:) in them (the other vars it handles well). I need to re-export all the original vars including the "form:id" and "form:mode" or ad_form cannot process the form... Should I file this as a bug, or is it intended to work this way? I am also not sure I'm using the correct syntax.

Thanks in advance,

Collapse
Posted by Ola Hansson on
Oops!

The way I have implemented this,
ad_form sends the form data to the spellchecker button by doing:

should read:

The way I have implemented this,
ad_form sends the form data to the _spellchecker_ by doing:

/Ola

Collapse
Posted by Dave Bauer on
Ola,

Did you try implementing the spellchecker as a -confirm-template using ad_form?

Collapse
Posted by Ola Hansson on
Nope.

I copied the the confirm-template code in ad form and made a similar spellcheck-template functionality. That might be a bad idea, though. I think being able to specify both templates concurrently is needed because the user might hit "OK" instead of "Check" and should be shown the confirm-template. If "Check" is clicked the spellchecker will provide its own confirmation (that's how it is now anyway) and the real confirm-template won't be displayed on top of that...

Hmm... Maybe it is possible to integrate with acs-templating/resourses/forms/confirm-button.* in some way...

Collapse
Posted by Lars Pind on
Ola,

I ran across this myself a short while ago when I did the changes to the form builder.

The problem is that export_vars lets you define types for your variables, akin to ad_page_contract, such as:

[export_vars { bug:array checked:multiple }]

So it splits on the colon.

The fix I did then was to allow you to escape colons, like thisÆ

[export_vars { form\:id form\:mode }]

You'll find this syntax present in acs-templating/tcl/form-procs.tcl.

This isn't the prettiest of solutions. Perhaps another solution would be to have a switch that says "-nosomething" which lets you turn off the :-interpretation alltogether.

Alternatively, we could change the form builder's habit of using :'s in variable names, replace them with dots, for example, since the form builder is the only piece of code that uses those colons, and it's nice to have the symmetri between ad_page_contract and export_vars.

Any other suggestions?

/Lars

Collapse
Posted by Don Baccus on
I've been wanting to get rid of the colons because when writing javascript widgets for Greenpeace I couldn't figure out any way to use a colon in a javascript variable.  In fact being able to include a colon in an identifier is fairly unusual.

So I used double-underbar for the "__refreshing_p" hidden var.

dot often has special meaning in other languages so I think I'd favor use of double-underbar, since underbars are commonly supported and especially since they cause no problems in JavaScript ...

Collapse
Posted by Jon Griffin on
If no one has started on this, I will take a stab at it.

If someone has let me know.

Collapse
Posted by Ola Hansson on
Thanks Lars,

This does not work:

set entire_form [export_vars -form -entire_form -override { {merge_p 1} } { info_vars form\:id form\:mode }]

(I do have the "!!cOlOn!!" stuff in utilities-procs.tcl 😊 )

Do you see what's wrong?

In my case the "form:*" vars are not set, but only exist in the current form. I could of course set them with [ns_set get $form form:id], etc (I tried both ways but neither would work).

Jon, you're more than welcome to start with this as far as I'm concerned. Please post here when you're done. Thanks!

Collapse
Posted by Lars Pind on
Yeah, export_vars only knows to look for variables in the local scope.

Use

export_vars ... { info_vars { form\:id {[ns_queryget "form:id"]} } { form\:mode {...similar...}} }

In other words, if an element in the vars list is a two-tuple, export_vars will do a 'subst' on the second element and use that as the value.

See the API-doc for export_vars, this is all explained there.

/Lars

Collapse
Posted by Ola Hansson on
Thanks Lars. That stuff finally works.

I have made a patch for the spellchecker against a recent check-out from HEAD and I put it here: https://openacs.org/bugtracker/openacs/bug?bug%5fnumber=165

In summary, here's what the patch contains and where I've put stuff... If you don't like where I've put procs and files, I'll make a new patch. Also if you have questions or suggestions for improvements, please post them here.

Added files:

- acs-templating/resources/forms/spellcheck.adp
- acs-templating/resources/forms/spellcheck.tcl
This is the main spellcheck template that one may include in ones local "-spellcheck_template".

- acs-templating/resources/forms/spelling-dictionary-add-to.tcl
A script that lets you add words to a global dictionary file (ispell-words - it gets created in this dir upon addition of the first word). Adding words prevent them from getting "caught" in the future.

- acs-templating/resources/forms/webspell
ispell-wrapper which sets the HOME env variable (this is the file where you choose between ispell or aspell and set the correct path to it, etc).

Changed files:

- acs-tcl/tcl/formprocessing-procs.tcl

Modifications to ad_form include; added support for spellchecking, documentation of the new switches and an example of their use.

I also added two procs related to spellchecking in this library file - the actual spellchecking proc and a helper.

- acs-templating/tcl/form-procs.tcl

Added code which determines whether the "Check Spelling" button should be displayed at all and whether it should have a custom label (if "-spellcheck-label" is specified).

I think this is mosty it.

In this version there's only support via using ad_form but perhaps, if there is a need for it, we can try to make it work from the form builder, too...

Collapse
Posted by Ola Hansson on
Oh yes!

The patch also makes Lars' new -edit_buttons and -actions switches available to ad_form.

Roberto, if you were working on those switches too, I hope I don't cause you inconvenience!