krause
I'm new here

select/deselect all checkboxes in a form

Hey community,

I'd like to create the functionality to select and deselect all checkboxes in a form (cause there are a lot of them...).

The checkboxes are dynamically created by my own checkbox component, it works very well.

I guess the only way to call a script for doing this is a FS_BUTTON, where I can leave an onClick-routine. So I have two buttons: "select all" and "deselect all", calling the appropriate scripts.

But I don't know how to access my form elements via script. Ok, I can transfer the checkbox elements via

<PARAMS>

     <PARAM name="checkbox1">#field.pt_checkbox1</PARAM>

     <PARAM name="checkbox2">#field.pt_checkbox2</PARAM>

     <PARAM name="checkbox3">#field.pt_checkbox3</PARAM>

</PARAMS>

But that's not very smart because my checkboxes are dynamically created and I don't want to loose this advantage...

Leaving this aside:

For each checkbox component I'd like to get all values and set the selectedValues to these values (to select all checkboxes).

Something like

String[] checkboxValues = checkboxComponent.getAllValues();

checkboxComponent.setSelectedValues(language, checkboxValues);

But on script side the Class of the checkbox element is "de.espirit.firstspirit.client.gui.FormAgentImpl$FormAgentFormField", so I cannot access via getAllValues() and setSelectedValues(). Is there any way to cast the FormField to a checkbox FormField or the like?

If I know the checkbox values I would be able to check them with the following code, but I don't know them...

Set set = new HashSet();

set.add("1");

set.add("2");

set.add("3");

checkbox.set(set);

Does anyone have a simple solution to iterate over all form elements an select/deselect all checkbox elements? Ideally without knowing the checkbox names.

I can't belive this is an unusual requirement Smiley Happy

Thanks a lot,

Steffi

FirstSpirit Client 4.2.446.45868

Server:xxx.local:8000 (HTTP)

Version Server: 4.2.446.45868

Speicher: 217,74 von 494,94 MByte belegt

Java Version: 1.6.0_25 32bit Sun Microsystems Inc.

Betriebssystem: Windows 7 6.1 x86

0 Kudos
6 Replies
krause
I'm new here

I also tried to set the default values of all checkboxes to "unchecked". With the following code I thought I could get the default values for my "disable_all_checkboxes" script, but it doesn't work.

checkbox.setToDefault();

I get an UnsupportedOperationException:

Caused by: java.lang.UnsupportedOperationException

    at de.espirit.firstspirit.client.gui.FormAgentImpl$FormAgentFormField.setToDefault(FormAgentImpl.java:130)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

...

The API tells me this exception is thrown "If the field does not support setting its value".

So how can I check and uncheck these rebellious checkboxes???

Thanks,

Steffi

0 Kudos
feddersen
Community Manager

Stefanie Krause schrieb:

The checkboxes are dynamically created by my own checkbox component, it works very well.

Have you implemented a custom component or do you use the CMS_INPUT_CHECKBOX component?

0 Kudos

Hey Christoph,

thanks for your reply.

It is a custom checkbox component (CMS_INPUT_CHECKBOX_CUSTOM_XY) leaning on the CMS_INPUT_CHECKBOX component.

0 Kudos

Ok, how does your form look like?

I'm a bit confused because of

<PARAMS>

     <PARAM name="checkbox1">#field.pt_checkbox1</PARAM>

     <PARAM name="checkbox2">#field.pt_checkbox2</PARAM>

     <PARAM name="checkbox3">#field.pt_checkbox3</PARAM>

</PARAMS>

Do you have three checkbox components in your form?

0 Kudos

I have 16 CMS_INPUT_CHECKBOX_CUSTOM_XY-components with 1-n values. These values and labels are read from a database.

The form looks like:

<CMS_INPUT_CHECKBOX_CUSTOM_XY name="pt_permissions_1_16">

     <CMS_INCLUDE_OPTIONS type="public">

          <NAME>IncludeServiceOption_1_16</NAME>

     </CMS_INCLUDE_OPTIONS>

     <LANGINFOS>

          <LANGINFO lang="*" label="right 1_16" description=""/>

     </LANGINFOS>

</CMS_INPUT_CHECKBOX_CUSTOM_XY>

<CMS_INPUT_CHECKBOX_CUSTOM_XY name="pt_permissions_1_17">

     <CMS_INCLUDE_OPTIONS type="public">

          <NAME>IncludeServiceOption_1_17</NAME>

     </CMS_INCLUDE_OPTIONS>

     <LANGINFOS>

          <LANGINFO lang="*" label="right 1_17" description=""/>

     </LANGINFOS>

</CMS_INPUT_CHECKBOX_CUSTOM_XY>

...

According to that i guess my button could be something like

      <FS_BUTTON name="pt_select_all_tags" noBreak="yes" onClick="script:select_all_tags">

        <LANGINFOS>

          <LANGINFO lang="*" label="select all" description="select all"/>

        </LANGINFOS>

        <PARAMS>

               <PARAM name="checkbox1">#field.pt_permissions_1_16</PARAM>

               <PARAM name="checkbox2">#field.pt_permissions_1_17</PARAM>

               <PARAM name="checkbox3">#field.pt_permissions_1_18</PARAM>

        </PARAMS>

      </FS_BUTTON>

0 Kudos

Correct, you'll need a param for every component. So you'll need to iterate over all params and use the OptionModel to select/deselect options. Working with the Option is explained within the Checkbox example.

0 Kudos