Custom form - $form_state contains only the max value.

Created on 14 July 2019, over 5 years ago
Updated 10 July 2024, 4 months ago

Hi,

I have a custom form in which I have the following field:

$form['price_range'] = [
      '#type' => 'container',
      '#attributes' => [],
      'slider-price-range' => [
        '#type' => 'slider',
        '#input' => TRUE,
        '#title' => NULL,
        '#input_title' => '',
        '#animate' => FALSE,
        '#disabled' => FALSE,
        '#max' => 255000,
        '#min' => 1000,
        '#step' => 1,
        '#orientation' => 'horizontal',
        '#range' => TRUE,
        '#default_value' => [1000, 255000],
        '#slider_style' => NULL,
        '#size' => 3,
        '#display_inputs' => FALSE,
        '#display_values' => TRUE,
        '#display_values_format' => '%{value}%',
        '#display_bubble' => FALSE,
        '#display_bubble_format' => '%{value}%',
        '#slider_length' => NULL,
        '#display_inside_fieldset' => FALSE,
        '#adjust_field_min' => '',
        '#adjust_field_max' => '',
        '#multi_value' => TRUE,
        '#values' => [1000, 255000],
        //'#value' => [1001, 254000],
        '#group' => NULL,
        '#group_type' => 'same',
        '#group_master' => FALSE,
        '#validate_range' => TRUE,
        '#fields_to_sync_css_selector' => NULL,
        '#hide_slider_handle_when_no_value' => FALSE,
      ],
      '#states' => [
        'visible' => [
          [
            [':input[name="price"]' => ['value' => 'full_price']],
          ],
        ],
      ],
    ];

On submit, on $form_state I have only the max value selected.
Am I doing something wrong? I need also the min value selected.

Thanks in advance for your help.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇷🇴Romania sorina.hriban

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India manishsaharan New Delhi

    I am requesting to Re-open this issue.
    After using #3 suggestion, still not getting 'from' value on the form submit inside $form_state.

    $form['price']['range'] = [
          '#type' => 'container',
          'widget' => [
            'slider-price-range-from' => [
              '#type' => 'hidden',
            ],
            'slider-price-range-to' => [
              '#type' => 'slider',
              '#input_title' => '',
              '#animate' => 'default',
              '#disabled' => FALSE,
              '#min' => 1,
              '#max' => 50,
              '#step' => 1,
              '#orientation' => 'horizontal',
              '#range' => TRUE,
              '#multi_value' => TRUE,
              '#size' => 10,
              '#display_inputs' => FALSE,
              '#display_values' => FALSE,
              '#display_values_format' => '$%{value}%',
              '#display_bubble' => TRUE,
              '#display_bubble_format' => '$%{value}%',
              '#slider_length' => '200px',
              '#display_inside_fieldset' => FALSE,
              '#validate_range' => TRUE,
              '#hide_slider_handle_when_no_value' => FALSE,
              '#fields_to_sync_css_selector' => [
                0 => '[name="slider-price-range-from"]',
                1 => '[name="slider-price-range-to"]',
              ],
              '#values' => [10, 40],
            ],
          ],
          '#states' => [
            'visible' => [
              ':input[name="price[value][custom]"]' => ['checked' => TRUE],
            ],
          ],
        ];
    
Production build 0.71.5 2024