Forum OpenACS Development: Re: ad_form refreshing

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

ad_form provides the special __refreshing_p to trigger the -on_refresh section where you can do whatever you want.

The idea is to stop the form processing and to do an intemediate submit where all the form elements from the beginning to the element triggering the submit are available.

The following example shows how to populate the element wh_mov_location_id with only the locations related to the store specified by the preceding element.


{wh_mov_store_id:integer(select)
{options { {"Choose" ""} [db_list_of_lists query "
select store_description, store_id
from mis_stores
where plant_id = :plant_id
order by plant_id, store_description
"] }}
{label {Store}}
{html {onChange "document.lineaddedit.__refreshing_p.value='1';document.lineaddedit.submit()"}}
}

{wh_mov_location_id:integer(select),optional
{options { {"Choose" ""} [db_list_of_lists query "
select w.plant_code || ' Store ' || s.store_code || ' ' || l.location_code, l.location_id
from mis_store_locations l, mis_stores s, mis_plants w
where s.store_id = :wh_mov_store_id and
l.store_id = s.store_id and
s.plant_id = w.plant_id
order by w.plant_code, s.store_id, l.location_code
"] }}
{label {Location}}
}

This case is very simple and you don't even need a -on_refresh section.

Collapse
3: Re: ad_form refreshing (response to 2)
Posted by Iuri Sampaio on
Claudio,

I tried to use your sample but it didn't work as expected.

I believe the "refreshing" is not working properly.
in the form. Whether i change the values from parent field or not, none action has been taken, in order to get new values.
It means the new values of the other field don't change respectively.

Maybe it happens because there are some constraints i need to add such as if statements in case the country field chosen has none sub-items(e.g cities).

Collapse
4: Re: ad_form refreshing (response to 3)
Posted by Iuri Sampaio on
here it is the piece of code i am talking about.

as you said it is very basic and i see no error on it that could possibly be blocking the "refreshing effect"

ad_form -name cal_item -export { return_url } -form {
{calendar_id:integer(select)
{label "[_ calendar.Sharing]"}
{options $calendar_options}
{html {onChange "document.lineaddedit.__refreshing_p.value='1';document.lineaddedit.submit()"}}
}

#set cal_item_types [calendar::get_item_types -calendar_id $calendar_id]
#if {[llength $cal_item_types] > 1} { }

{item_type_id:integer(select),optional
{label "[_ calendar.Type_1]"}
{options { {"Choose" ""} [calendar::get_item_types -calendar_id $calendar_id] } }
{help_text "[_ calendar.Type_Help]"}
}
... (rest of the form) ...

}

Collapse
5: Re: ad_form refreshing (response to 4)
Posted by Claudio Pasolini on
The line:

{html {onChange "document.lineaddedit.__refreshing_p.value='1';document.lineaddedit.submit()"}}

shoid read:

{html {onChange "document.cal_item.__refreshing_p.value='1';document.cal_item.submit()"}}

Remember to add calendar_id to the parameters of ad_page_contract.

Collapse
6: Re: ad_form refreshing (response to 5)
Posted by Iuri Sampaio on
good! i was paying atention to ad_form -name

I fixed and now i get the refreshing behavior working well. Although the values is still not properly set.

It gets stuck on the last values of the list of ids and no matter we change the parent field the id never changes

yes, i did put $cal_id in ad_page_contract parameters.

I put $cal_id also as label of the field just to see what was into the var $cal_id,


{cal_id:integer(select)
{label "[_ calendar.Sharing]"}
{options { {"Select" ""} $calendar_options} }
{html {onChange "document.cal_item.__refreshing_p.value='1';document.cal_item.submit()"}}
}

#set cal_item_types [calendar::get_item_types -calendar_id $calendar_id]
#if {[llength $cal_item_types] > 1} { }

{item_type_id:integer(select),optional
{label "$cal_id [_ calendar.Type_1]"}
{options { {"Choose" ""} [calendar::get_item_types -calendar_id $cal_id] } }
{help_text "[_ calendar.Type_Help]"}

Collapse
7: Re: ad_form refreshing (response to 6)
Posted by Iuri Sampaio on
Nevermind,

I had $cal_id being used in another part of the code and that was causing conflict. it was overwriting the ad_form values.

thanks, it works fine now! ad_form is just wonderful ;)

Collapse
8: Re: ad_form refreshing (response to 7)
Posted by Iuri Sampaio on
When the form get refreshed it misses some vars. Those vars can not be missed, otherwise actions get switched.

how does I refresh the form passing the vars needed?