Re: how to obtain selected values in a multi-value dropdown
"Paul G. Joseph" <[email protected]>
| Newsgroups | gmane.text.xml.cocoon.user |
|---|---|
| Message-ID | <[email protected]> |
Got it! Will so do. Thanks again!
Paul
On 10/15/2013 3:25 AM, Robby Pelssers wrote:
> Hi Joseph,
>
> good that you solved the issue. I still think however that when using a valuechanged event it's better not to ask the source for it's value but just call the getNewValue() on the event itself.
>
> What you are running into is probably the issue of converting a Java object to a javascript object.
>
> You could write some utility functions in a common JS file and include them in your page. That will
> (a) keep you from writing the same nasty code multiple times
> (b) remove the need to escape e.g. < into <
>
> ******************************
> formhelper.js
> *******************************
> function arrayToList(array) = {
> var list = new java.util.ArrayList();
> for(var i=0; <array.length; i++) {
> list.add(value[i]);
> }
> }
>
> ******************************
> formdefinition.xml
> *******************************
>
> <fd:on-value-changed>
> <javascript>
> var values= arrayToList(event.getNewValue())
> </javascript>
> </fd:on-value-changed>
>
> Didn't test this but it should work in my opinion.
>
> Cheers,
> Robby
>
> R?ntgenlaan 27 | 2719 DX Zoetermeer
> www.the-future-group.com
> +31 (0)79 - 363 2905
> http://twitter.com/futuregroup
>
> 06 15879926
> [email protected]
>
> ________________________________________
> Van: Paul G. Joseph [[email protected]]
> Verzonden: maandag 14 oktober 2013 15:45
> To: [email protected]
> Onderwerp: Re: how to obtain selected values in a multi-value dropdown
>
> Hi Robby,
>
> Thanks for your email. I wasn't able to get this to work...but was able
> to work around this problem as shown below.
>
> <fd:on-value-changed>
> <javascript>
> var value = event.source.getValue();
> var collection = new java.util.ArrayList();
> for(var i=0; i<value.length; i++) {
> collection.add(value[i]);
> }
> </javascript>
> </fd:on-value-changed>
>
> Thanks again for your help.
> Paul
>
> On 10/14/2013 3:53 AM, Robby Pelssers wrote:
>> >From the looks of it a org.apache.cocoon.forms.event.ValueChangedEvent has this interface
>>
>>
>> Method Summary
>> Object getNewValue()
>>
>> Object getOldValue()
>>
>>
>> why don't you just try
>>
>> var newvalues = event.getNewValue();
>>
>> I'm assuming now that this is an array in the multiselect case.
>>
>> If that doesn't work... let me know.
>>
>> Robby
>> Schrijf je nu alvast in voor het TFG Innovation Event 2013 op 30 oktober
>>
>> R?ntgenlaan 27 | 2719 DX Zoetermeer
>> www.the-future-group.com
>> +31 (0)79 - 363 2905
>> http://twitter.com/futuregroup
>>
>> 06 15879926
>> [email protected]
>>
>> ________________________________________
>> Van: Paul G. Joseph [[email protected]]
>> Verzonden: woensdag 9 oktober 2013 22:24
>> To: [email protected]
>> Onderwerp: how to obtain selected values in a multi-value dropdown
>>
>> Hi there,
>>
>> I am using Cocoon 2.1.11 and CForms/Javascript/Java in Tomcat.
>>
>> In a form (say myform.xml) I have two fields--both dropdowns. One is
>> multi-select, the other not.
>>
>> The multiselect field is as below:
>>
>> <fd:multivaluefield id="MULTI" required="false">
>> <fd:datatype base="string"/>
>> <fd:selection-list>
>> <fd:item value="Cat"/>
>> <fd:item value="Dog"/>
>> <fd:item value="Mouse"/>
>> </fd:selection-list>
>> <fd:on-value-changed>
>> <javascript>
>> debug("Came here 1");
>> var value = event.source.value;
>> debug("value is: " + value);
>> </javascript>
>> </fd:on-value-changed>
>> </fd:field>
>>
>> The other (no multi-select) is as follows:
>>
>> <fd:field id="SINGLE" required="false">
>> <fd:datatype base="string"/>
>> <fd:selection-list>
>> <fd:item value="Lion"/>
>> <fd:item value="Tiger"/>
>> <fd:item value="Bear"/>
>> </fd:selection-list>
>> <fd:on-value-changed>
>> <javascript>
>> debug("Came here 2");
>> var value = event.source.value;
>> debug("value is: " + value);
>> </javascript>
>> </fd:on-value-changed>
>> </fd:field>
>>
>> Then in my log, when I select multiple values (say Cat and Mouse) in the
>> first and a single value (say Tiger) in the second I get:
>> 10/09/2013 16:16:00 PM: DEBUG: Came here 1
>> 10/09/2013 16:16:00 PM: DEBUG: value is: [Ljava.lang.Object;@8c3fe4
>> 10/09/2013 16:16:00 PM: DEBUG: Came here 2
>> 10/09/2013 16:16:00 PM: DEBUG: value is: Tiger
>>
>> Question: how do I get the actual values that the user chose (say Cat
>> and Mouse) in the multi-value field? Should I use a different method
>> than the one I used for the single select field and which seems to work?
>>
>> Paul
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>