drupal commerce - свое поле количества

Главные вкладки

Аватар пользователя ma3 ma3 7 мая 2020 в 18:01

Добрый день. Хотел бы сделать поле количество с кнопками + - . Знаю что есть модуль, но он не сильно надежен насколько я понял. Искал варианты решения , но так ничего не нашел. В Form api тоже решения не увидел.

родное поле:

<div class="form-item form-item-quantity form-type-textfield form-group"> <label class="control-label" for="edit-quantity">Количество</label>
<input class="form-control form-text" type="text" id="edit-quantity" name="quantity" value="1" size="5" maxlength="128"></div>

я хотел бы получить:

<div class="stepper stepper--style-2 js-spinner">
            <input autofocus="" type="number" min="0" max="100" step="1" value="0" class="stepper__input" data-stepper-debounce="400">
            <div class="stepper__controls">
                <button type="button" spinner-button="up">+</button>
                <button type="button" spinner-button="down">-</button>
            </div>
        </div>

Подскажите куда копать?

Комментарии

Аватар пользователя ma3 ma3 8 мая 2020 в 15:58

вот что удалось придумать:

function PRONOGOTKI_form_alter(&$form, &$form_state, $form_id) {

if (!empty($form['quantity']))
{
$form['quantity']= array(
  '#type' => 'textfield',
  '#attributes' => array(
    ' type' => 'number', // insert space before attribute name Smile
    ' class' => 'stepper__input',
    ' min' => '1',
),
  '#title' => t(''),
  '#field_prefix' => '<div class="stepper stepper--style-2 js-spinner">',
  '#field_suffix' => '<div class="stepper__controls"><button type="button" spinner-button="up">+</button><button type="button" spinner-button="down">-</button></div></div>',
  '#precision' => 10,
  '#decimals' => 2,
  '#minimum' => 0,
  '#maximum' => 123456.99,
  '#default_value' => 1,
);

}

}

результат :