简体   繁体   中英

How do I change the default value of my JQuery slider

I'm trying to change the default value of my slider to halfway along.

You can see at the moment it sits on the far left:

滑块的图像

My Jquery code snippet is as follows:

 $form['stepX'][$key] = array('#type' => 'fieldset', '#attributes' => array('class' => array('wb_spc_question_fieldset')));
      $form['stepX'][$key]['header'] = array('#markup' => '<div class="wb_spc_select_group_title">' . $section['name'] . '</div>');
      $form['stepX'][$key]['columns'] = array('#markup' => '<div class="wb_spc_column now">' . t('Now') . '</div><div class="wb_spc_column future">' . t('Future') . '</div>');
        $form['stepX'][$key]['values'] = array('#type' => 'fieldset');
        $form['stepX'][$key]['values'][] = array('#markup' => '<span class="wb_spc_select_span">' . $section['description'] . '</span>');

        $form['stepX'][$key]['values']['now'] =  array(
            '#type' => 'slider',
            '#animate' => 'fast',
            '#max' => 10,
            '#min' => 1,
            '#orientation' => 'horizontal',
            '#step' => 1,
            '#default_value' => empty($form_state['storage']['values']['stepX'][$key]['now']['value']) ? '4' : $form_state['storage']['values']['step'][$key]['now']['value'],
            '#slider_style' => 'orange',
            '#size' => 1,
            '#display_inputs' => FALSE,
            '#display_values' => TRUE,
            //'#display_bubble' => TRUE,
           // '#slider_length' => '100%',
            '#attributes' => array('class' => array('wb_spc_select')),
          );  

        $form['stepX'][$key]['values']['future'] = array(
            '#type' => 'slider',
            '#animate' => 'fast',
            '#max' => 10,
            '#min' => 1,
            '#orientation' => 'horizontal',
            '#step' => 1,
            '#default_value' => empty($form_state['storage']['values']['step' . $step][$key]['future']['value']) ? '8' : $form_state['storage']['values']['step' . $step][$key]['future']['value'],
            '#slider_style' => 'orange',
            '#size' => 1,
            '#display_inputs' => FALSE,
            '#display_values' => TRUE,
           // '#display_bubble' => TRUE,
           // '#slider_length' => '100%',
            '#attributes' => array('class' => array('wb_spc_select')),
          );  

      if(isset($section['body'])){
        $form['stepX'][] = array('#markup' => $section['body']);
      }

  }

This is all part of a custom Drupal module.

Many thanks.

By the looks of things your solution probably lies in the line

'#default_value' => empty($form_state['storage']['values']['stepX'][$key]['now']['value']) ? '4' : $form_state['storage']['values']['step'][$key]['now']['value'],

Try changing it to:-

'#default_value' => '50',

It looks like it just empties everything by default, thus causing it to stay at 0, i could be wrong though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM