Forum OpenACS Development: ad_form and [] in options

Collapse
Posted by Malte Sussdorff on
ad_form runs a "subst [lindex $extra_arg 1]" on options passed in. This breaks if the title of an option is something like "MyFile[1].doc". We ran into this problem a couple of times and I am probably going to write a general filter to rename file_names accordingly (so no use of [] {} + in the file name), but the better solution would probably be to teach ad_form not to break with "command not found "1"". Any idea if I could do something about it savely or is it in purpose that the option label is evaluated within ad_form?
Collapse
Posted by Dave Bauer on
I believe it is supposed to be evaluated so [_ message.key] works (among other things)

Maybe we need more clear documentation

You can use a regsub or string replace to escape the characters, although that seems error prone as well.

Maybe Don has an idea.

Collapse
Posted by Rocael Hernández Rizzardini on
Right, we have detected the same problem. Probably one good solution is to have specific notation for interpret things (for instance [__ means actually execute the proc inside), and everything else should not be executed.
regsub will make the things harder to maintain since there are many cases.

[_ should be allowed as well for i18n.

Collapse
Posted by Malte Sussdorff on
So, should we form a TIP around this, stating that anything starting with "[__" will be executed, as will "[_" but nothing else? And if yes, would removing the "subst" be enough?
Collapse
Posted by Gustaf Neumann on
another option is to provide options to [_ ...], such as [_ -subst ....] or even provide the options of subst as options to _ (whoa, a sentence with 4 options).
Collapse
Posted by Dave Bauer on
Wait a minute!

the _ proc is not behaving unexpectedly, but ad_form, so we need to pass subst options to the various ad_form elements
ie:

{label -noprocs $some_var}

right?

Collapse
Posted by Malte Sussdorff on
Your idea would work as well, but would require to rewrite a whole bunch of applications (adding the noprocs switch), though this would not require a TIP. Either way is fine with me, I will have to do this though over the weekend.
Collapse
Posted by Rocael Hernández Rizzardini on
_ is the i18n proc, and that one is working fine, and should be allowed to execute always.
adding an explicit option will be good, though instead of -noprocs, better -allowprocs or something like that, because in most of the cases no-procs is what you want, isn't it?
I don't think the - will be needed, just:
{label allowprocs $var}
Collapse
Posted by Dave Bauer on
Malte,

Can we see the exact call to ad_form that is causing the problem? I am not sure if you pass a reglar variable that it will call the subst on the value of the variable, or the name of the variable. So please provide a reproducible example we can discuss.

Collapse
Posted by Malte Sussdorff on
Sure. Here you go:
if {$parent_id == $root_folder_id} {
                lappend files [list "$title ($content_size bytes)" $object_id]
            } else {
                lappend files [list "$title ($content_size bytes) ($foldername)" $object_id]
            }

ad_form -extend -name freelancer -form [list [list file_ids.${folder}:text(checkbox),multiple,optional [list label "[_ mypack.Folder] $folder_name"] [list options $files]]]
}
And the issue is that $title can have the values:
  • myfile[1].doc or
  • myfile{1}.doc or
  • my$file.doc
Collapse
Posted by Dave Bauer on
Malte

This would solve your problem:

ad_form -extend -name freelancer -form { {file_ids.${folder}:text(checkbox),multiple,optional [list label "[_ mypack.Folder] $folder_name"] [list options $files]}}

and be alot simpler than rewriting ad_form.

Using curly braces delays the evaluation you are actually passing the value of the options variable to ad_form instead of the name.

Collapse
Posted by Torben Brosten on
Is util::subst_safe indicated here?
Collapse
Posted by Malte Sussdorff on
The question is what would subst_safe do? I could imagine:

run a subst in a catch. if Error, just return the value passed in. That would probably be the easiest and non TIP requiring fix, but I am not sure if it is the best one.