This application is not used any more and exists only for history. Post new tickets on the Github account.
Cette application n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #565 (confirmed enhancement)

Opened 6 years ago

Last modified 3 years ago

jforms: support of <switch>

Reported by: laurentj Owned by:
Priority: normal Milestone:
Component: jelix:forms Version: 1.0.3
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

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

comment:1 Changed 6 years ago 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>

comment:2 Changed 6 years ago 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.

comment:3 Changed 6 years ago 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.

comment:4 Changed 6 years ago by bballizlife

I'm ok with that proposal

comment:5 Changed 3 years ago by laurentj

  • Status changed from new to confirmed
Note: See TracTickets for help on using tickets.