Ticket #565 (new enhancement)

Opened 3 months ago

Last modified 3 months ago

jforms: support of <switch>

Reported by: laurentj Assigned to:
Priority: normal Milestone:
Component: jelix:forms Version: 1.0.3
Severity: normal Keywords:
Cc: Php version:
Review: Hosting Provider:
Documentation needed: 0 Blocking:

Description

<switch> activate some controls depending of a value.

<switch ref="test">
    <case value="aaa">
       <input ref="first"> ...</input>
    </case>
    <case value="bbb">
       <menulist>...</menulist>
       <checkbox>...</checkbox>
    </case>
    <case value="ccc">
       <output />
    </case>
</switch>

Here, if the value of test is "aaa" then the input will be shown, but not the menulist, the checkbox and the output. If its value is "bbb", then only the menulist and the checkbox will be shown, etc.

Change History

04/28/08 15:56:28 changed by mike

Laurent, I need this feature too. I think it could improve jforms a lot !!

But can you tell me if you plan to do a live modification (in javascript) of the form without reload? For example can you do the thing below?

<menulist ref="test">
      <label>Choix?</label>
      <item value="aaa">Choix A</item>
      <item value="bbb">Choix B</item>
      <item value="ccc">Choix C</item>
</menulist>
<switch ref="test">
    <case value="aaa">
       <input ref="first"> ...</input>
    </case>
    <case value="bbb">
       <menulist>...</menulist>
       <checkbox>...</checkbox>
    </case>
    <case value="ccc">
       <output />
    </case>
</switch>

According to the value of the menulist control named "test", the form automatically displays the controls written in the switch control.

The attribute shouldn't be "ref" but maybe something like "linkto" or anything else.

<switch ref="switchtest" linkto="test">...</switch>

04/28/08 18:01:46 changed by laurentj

No, it won't do such thing. the switch will act only in the server side, and will only have effect on the HTML generation. No "live" modification for the moment.

So ticket #567 for future dynamic behaviors. And before, the ticket #564 will do almost what you want.

05/02/08 17:02:23 changed by laurentj

Additionnal specifications.

the switch element could have a label element. If we deactivate the switch or if we mark it as readonly, all its sub-controls will be deactivated or readonly.

For the template part:

If the control is displayed throw a formcontrols loop or by formfull, it will generate a default html content like this:

<fieldset><legend>The label of the switch</legend>
<table> <!-- list of controls of the selected case -->
  <tr><th>here the label</th><td>here the control</td></tr>
  <tr><th>here the label</th><td>here the control</td></tr>
  <tr><th>here the label</th><td>here the control</td></tr>
</table>
</fieldset>

If we want to personnalize the output, we would use the form_control_switch plugin. Example which generates the same content as the default html generation like above:

    {form_control_switch 'action', '<fieldset><legend>%s</legend><table>', '</table></fieldset>'}
        {form_controls}
        <tr><th>{ctrl_label}</th><td>{ctrl_control}</td></tr>
        {/form_controls}
    {/form_control_switch}

this plugin loops over all controls of the selected case. The second and third argument of form_control_choice are the content before and after the list of items. "%s" is replaced by the label of the choice.

All comments are welcomed.

05/02/08 17:27:42 changed by bballizlife

I'm ok with that proposal

Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed