Forum OpenACS Development: ad_form element link

Collapse
Posted by Iuri Sampaio on
Hi there,

I want to have two ad_forms working together. Well not quite together.
The scenario is when the user wants to add an item he goes to the respective ad_form.
Then in the middle of the ad_form attributes (elements), there is a link to take the user to another ad_form to add some info aside the first one.

What ad_form's element should i use to create a link in the midle of an ad_form?

Intuitivelly the element should be somehting like an action. But actions get the ad_form submited when executed.
I found something similar on calendar package. This simple ad_form has its own action button.

ad_form -name add-new-item-type -action item-type-new -has_submit 1 -form {
{calendar_id:text(hidden)
{value $calendar_id}
}
{type:text,nospell
{label "[_ calendar.New_Type]"}
{html {size 20}}
}
{btn_ok:text(submit)
{label "[_ calendar.add]"}
}
}

The diference is i don't want to submit the form.
I just want to take the user to another page with another ad_form, assuming he was in the first page with the first ad_form.
Then take the user back to the first ad_form after he has submited the second one.

Any clues how to figure it out?

Collapse
2: Re: ad_form element link (response to 1)
Posted by Claudio Pasolini on
Hi Iuri,

you could use JavaScript to open a new window.

For example you can add to a field of the first form a specification like:

{html {onChange "javascript:window.open(....)}}

You can also pass parameters to the second window and receive back a result in one or more fields of the first form.

Collapse
3: Re: ad_form element link (response to 2)
Posted by Iuri Sampaio on
Option two is the one i would choose.

The issue i was stuck is the piece of code bellow. It's easier this way.

ad_form -extend -name bug -form {
{info4:text(inform),optional
{label ""}
{value "Adicionar Contato"}
}
}

by the way, about the javascript code...
is there a command to use in order to refresh the form.
I use this one
{html {onchange "document.bug.__refreshing_p.value='1';document.bug.submit()"}}

But this command actually gets ad_form submitted instead of refreshed

Collapse
4: Re: ad_form element link (response to 3)
Posted by Dave Bauer on
Why do you want two seperate forms? You can do this of course. One way is to add another form in the html and hide it, then display it when the use clicks the "link". You can detect which form is selected on the back end, and use background javascript to submit the embedded form if necessary.

I'd need a little more information about exactly what you are trying to accomplish. This seems sort of complex, what is the ultimate goal you have that two seperate forms solves?

Collapse
5: Re: ad_form element link (response to 4)
Posted by Iuri Sampaio on
I am using bug-tracker package. I created three more roles on workflow package.
Then i want the members able to add members in the system in the time they are adding a bug.

The reason is that workflow pkg controls and searches its roles among the members in the system.

So, in the time the user is adding a bug and somehow he wants to assign the new role to a new member. So he needs to add him first, and then go back to the form.

I was wondering if this would be a good approach.
I think i could just use contacts package to do the job.

One of the goals is to have a database of contacts, and not necessarily members.
I am doing this approach just in case in the future we need them inside the system, plus to avoid having three more packages installed and more code to debug.

Collapse
6: Re: ad_form element link (response to 1)
Posted by Dave Bauer on
Right, so i would recommend either 1) a popup form that refreshes the parent window when its done (so the dropdown is updated. refreshing_p should work in ad_form...) or an ajax style form that lets you add the contact, then refreshes the dropdown for assignment with javascript.

Can you be more specific to why refreshing_p is not working for you?

Collapse
7: Re: ad_form element link (response to 6)
Posted by Iuri Sampaio on
When i use refreshing_p in the page bug.tcl

ad_form -name bug -form {
...
{component_id:integer(select)
{label "[bug_tracker::conn Component]"}
{options {[bug_tracker::components_get_options]}}
{mode display}
{html {onchange "document .bug.__refreshing_p,value='1';document.bug.submit()"}}
}

...}

the form gets submitted and it returns broken with the disabled fields fix_for_version, found_in_version, patches and etc.

Collapse
8: Re: ad_form element link (response to 1)
Posted by Dave Bauer on
Ok, so you need to figure out why that's not working then first. It refreshing_p is set correctly it should not process the form as a submit if you are using ad_form.
Collapse
9: Re: ad_form element link (response to 8)
Posted by Iuri Sampaio on
Hi dave,

It works fine on bug-add. An empty ad_form to add bugs.
However, it is broken on bug.tcl, the ad_form to submit actions to amend bugs. it needs deeper debug from myside


Furthermore, i would like to follow your approach and create an ajax pop up with user-new registration ad_form and after it is submitted, it makes the bug-add form to get refreshed. and allow users fill out with updated info.
Would you guide me building such a functionality?

I see the starting point is the link in the bug-add form. 

So far i just wrote an ad_form block with the chunk of code

ad_form -extend -name bug -form {
    {info1:text(inform),optional
        {label "<h1>Partes</h1>"}
        {value "<br><a href='/register/user-new' target='_blank'>Adicionar parte em Contatos</a>"}
    }
}

This works. Barely. it opens a new tab with the user-new form but after adding the new user, it still has to refresh manually.
 
I believe "value" block should be different. it should contain a javascript code. What would it be?
Collapse
10: Re: ad_form element link (response to 9)
Posted by Iuri Sampaio on
Nice!
Do you guys see how to trick links of the openacs.org system under forum input html tags?
Collapse
11: Re: ad_form element link (response to 10)
Posted by Dave Bauer on
Of course, if you use enhanced text or HTML format it will interpret your HTML tags. I changed your post of fixed-width text to see the code.
Collapse
12: Re: ad_form element link (response to 11)
Posted by Iuri Sampaio on
and do you have any hints in the post above?
Collapse
13: Re: ad_form element link (response to 1)
Posted by Dave Bauer on
Actually what you want to do is on submit in the popup form you want to cause the original script to submit wiht refreshing_p to reload.