You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christofer Dutz <du...@c-ware.de> on 2006/08/01 10:07:28 UTC

Accessing AJAX forms field values

Hi,

 

I am currently working on an cforms ajax application. Here when entering an
address, the user enters the country code of an address (the content is
provided by a suggestion-list and this works fine)

If he then starts entering the zip code only the zip codes for that
particular country should be shown. My first try was to access the form
model and get the other fields values. Unfortunately the model isn’t updated
until the form is really submitted. My next attempt was to extend the
CFormsSuggest.js in the forms-jar. Strangely I seem to be unable to access
any other form fields, even if I try to access them using the ids I found
using the IE Dom Developer Toolbar and by this definitively exist.

 

Any ideas of how I can build context-sensitive suggestion-lists.

 

Regards,

     Chris

 

[ c h r i s t o f e r   d u t z ]

 

IT-Berater

univativ GmbH & Co. KG

Robert-Bosch-Str. 7, 64293 Darmstadt

 

fon: 0 61 51 / 66 717 - 21

fax: 0 61 51 / 66 717 - 29

email: christofer.dutz@univativ.de

http://www.univativ.de

 

Darmstadt, Stuttgart, Karlsruhe, Düsseldorf

 

 


Re: AW: Accessing AJAX forms field values

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Grzegorz Kossakowski napisał(a):
> Christofer Dutz napisał(a):
>
> I have to think about it for a while, maybe come with better solution.


I think better solution is to use even more "push" method. In event 
handler of country widget you create new selectionList[1] basing on 
value of selected country and set this list as a suggestion list of zip 
widget.

<fd:field id="country">
<fd:on-value-changed>
<fd:javascript>
var country = event.sourceWidget.value;
//create selectionList
//[...]
event.sourceWidget.lookup("../zip").suggestionList = yourSelectionList;
<fd:javascript>
</fd:on-value-changed>
</fd:field>

*BUT* this won't work as there is now set method for suggestionList 
property (only get). It seems that clean solution demands little 
patching. Can you undertake of doing it?

[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/SelectionList.html

-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


AW: AW: Accessing AJAX forms field values

Posted by Christofer Dutz <du...@c-ware.de>.
Hi Grzegorz,

Well I am not using the ordinary approach. We used to generate plain old
selection lists. These were populated by internal pipelines. The initial
version of our suggestion-list support contained a function walking through
the dom of this pipelines result building the array of name-values the
suggestion-list generator expects. While debugging I found out that all this
does is to generate a selection-list and then to flatten that again. So we
took out the suggestion-list generator entirely. Here our current pipeline
for the suggestion-lists:

<!-- Pipeline for creating the suggestion list content -->
<map:match pattern="_cocoon/forms/suggest">
	<!-- the parameter "filter" contains the current content of 
		the textfield and "widget" the id of the currently active 
		widget. Knowing this it should be easily possible to use
		the SZT pipeline directly without the need for converting
		the content multiple times. -->
	<!-- the forms-content generator gets the from object from the
continuation the same way the suggestion-list generator dies and
creates a xml-representation of the forms values with the ids as
tag names and their values as content -->
	<map:generate type="forms-content"/>
	<!-- uses the values of the current form to dynamically 
		create a query -->
	<map:transform type="xslt-saxon" 
		src="selection-lists/suggestion-list-query.xslt"/>
	<!-- execute the query -->
	<map:transform type="sql"/>
	<!-- transform the result into a selection-list -->
	<map:transform type="xslt-saxon" 
		src="selection-lists/suggestion-list-trans.xslt"/>
	<!-- flatten the selection list, so the suggestion-list code can
work 		with the results -->
	<map:transform
		src="resource://org/apache/cocoon/forms/resources/selection-
list2json.xsl"/>
	<map:serialize type="text"/>
</map:match>

This way I should be able to have all the information I need unfortunately I
can't. I added a print command to the on-value-changed code of the country
widget and it is not executed when the field value changes. As a matter of
fact on-value-changed seems not to work at all with suggestion-list widgets.
It seems that this the problem. If I change the country-widget to a
non-suggestion-list, everything works fine. I'll post a question for this in
a separate thread.

Any other Ideas? Your approach will not work because of this problem. All
the fields Country, Zip and Town are String widgets with suggestion-lists.

Chris

-----Ursprüngliche Nachricht-----
Von: Grzegorz Kossakowski [mailto:grek@tuffmail.com] 
Gesendet: Dienstag, 1. August 2006 14:20
An: users@cocoon.apache.org
Betreff: Re: AW: Accessing AJAX forms field values

Christofer Dutz napisal(a):
> Hi Grzegorz,
>
> Thanks for your reply. In general your Idea sounds good. Could you explain
> what you mean by "seting an attribute of zip"? Is it possible to add
> additional attributes to a field? How can I access them when generating
the
> suggestion-list. Is there any sample code showing this?

Every CForms widget can have a collection of attributes, see [1].
Your country widget should look like:
<fd:field id="country">
<fd:on-value-changed>
<fd:javascript>
event.sourceWidget.lookupWidget("../zip").setAttribute("country", 
event.sourceWidget.value);
<fd:javascript>
</fd:on-value-changed>
</fd:field>

Taking a quick look on source of JavaScriptSelectionListBuilder[2] it 
seems that there is no way to access a widget object from implementation 
of suggestion-list. However, there is dirty workaround for this. You can 
put your form instance in viewdata in flowscript and then access it in 
from javascript code.

<fd:field id="zip">
<fd:suggestion-list type="javascript">
//your javascript code
</fd:suggestion-list>

I have to think about it for a while, maybe come with better solution.

[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/Widge
t.html
[2] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/JavaSc
riptSelectionListBuilder.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: AW: Accessing AJAX forms field values

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Christofer Dutz napisał(a):
> Hi Grzegorz,
>
> Thanks for your reply. In general your Idea sounds good. Could you explain
> what you mean by "seting an attribute of zip"? Is it possible to add
> additional attributes to a field? How can I access them when generating the
> suggestion-list. Is there any sample code showing this?

Every CForms widget can have a collection of attributes, see [1].
Your country widget should look like:
<fd:field id="country">
<fd:on-value-changed>
<fd:javascript>
event.sourceWidget.lookupWidget("../zip").setAttribute("country", 
event.sourceWidget.value);
<fd:javascript>
</fd:on-value-changed>
</fd:field>

Taking a quick look on source of JavaScriptSelectionListBuilder[2] it 
seems that there is no way to access a widget object from implementation 
of suggestion-list. However, there is dirty workaround for this. You can 
put your form instance in viewdata in flowscript and then access it in 
from javascript code.

<fd:field id="zip">
<fd:suggestion-list type="javascript">
//your javascript code
</fd:suggestion-list>

I have to think about it for a while, maybe come with better solution.

[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/Widget.html
[2] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/JavaScriptSelectionListBuilder.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


AW: Accessing AJAX forms field values

Posted by Christofer Dutz <du...@c-ware.de>.
Hi Grzegorz,

Thanks for your reply. In general your Idea sounds good. Could you explain
what you mean by "seting an attribute of zip"? Is it possible to add
additional attributes to a field? How can I access them when generating the
suggestion-list. Is there any sample code showing this?

Regards, 
     Chris

-----Ursprüngliche Nachricht-----
Von: Grzegorz Kossakowski [mailto:grek@tuffmail.com] 
Gesendet: Dienstag, 1. August 2006 10:33
An: users@cocoon.apache.org
Betreff: Re: Accessing AJAX forms field values

Christofer Dutz napisal(a):
>
> Hi,
>
> I am currently working on an cforms ajax application. Here when 
> entering an address, the user enters the country code of an address 
> (the content is provided by a suggestion-list and this works fine)
>
> If he then starts entering the zip code only the zip codes for that 
> particular country should be shown. My first try was to access the 
> form model and get the other fields values. Unfortunately the model 
> isn’t updated until the form is really submitted.
>

Have you considered changing method from pulling criteria to pushing it? 
I mean it should be country field's responsibility to inform about it's 
actual value. You can use onValueChanged event to set attribute of zip 
code field.
>
> My next attempt was to extend the CFormsSuggest.js in the forms-jar. 
> Strangely I seem to be unable to access any other form fields, even if 
> I try to access them using the ids I found using the IE Dom Developer 
> Toolbar and by this definitively exist.
>

I think it not a good practice to change JS client libraries just for 
special case. CForms are server side and we should focus on this :)

Hope this helps, if not, just ask more question.

-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Accessing AJAX forms field values

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Christofer Dutz napisał(a):
>
> Hi,
>
> I am currently working on an cforms ajax application. Here when 
> entering an address, the user enters the country code of an address 
> (the content is provided by a suggestion-list and this works fine)
>
> If he then starts entering the zip code only the zip codes for that 
> particular country should be shown. My first try was to access the 
> form model and get the other fields values. Unfortunately the model 
> isn’t updated until the form is really submitted.
>

Have you considered changing method from pulling criteria to pushing it? 
I mean it should be country field's responsibility to inform about it's 
actual value. You can use onValueChanged event to set attribute of zip 
code field.
>
> My next attempt was to extend the CFormsSuggest.js in the forms-jar. 
> Strangely I seem to be unable to access any other form fields, even if 
> I try to access them using the ids I found using the IE Dom Developer 
> Toolbar and by this definitively exist.
>

I think it not a good practice to change JS client libraries just for 
special case. CForms are server side and we should focus on this :)

Hope this helps, if not, just ask more question.

-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org