Radio buttons states

Created on 23 June 2023, over 1 year ago

How an undocumented functionality I found that we can use #states in radio buttons and this module.

We can define a radio this way:

$form['radiosfield'] = Array
(
    [#type] => radios
    [#title] => Title
    [#title_display] => before
    [#id] => payment_method
    [#options] => Array
        (
            [1] => opc 2
            [2] => Demo
            [3] => opc 3
            [4] => opc 4
        )

    [#options_attributes] => Array
        (
            [1] => Array
                (
                    [data-drupal-states] => {"visible":{":input[name=\u0022installments\u0022]":{"value":1}}}
                )

            [2] => Array
                (
                    [data-drupal-states] => {"visible":{":input[name=\u0022installments\u0022]":{"value":1}}}
                )

            [3] => Array
                (
                    [data-drupal-states] => {"visible":{":input[name=\u0022installments\u0022]":{"value":1}}}
                )

            [4] => Array
                (
                    [data-drupal-states] => {"visible":{":input[name=\u0022installments\u0022]":{"value":1}}}
                )
        )
)

The json in 'data-drupal-states' it's the #states array in json format.

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇪🇸Spain psf_ Huelva

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @psf_
  • First commit to issue fork.
Production build 0.71.5 2024