diff -u b/src/Form/RegcodeOperationsForm.php b/src/Form/RegcodeOperationsForm.php --- b/src/Form/RegcodeOperationsForm.php +++ b/src/Form/RegcodeOperationsForm.php @@ -149,10 +149,18 @@ * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if (empty($form_state->getValue('count')) + $count = $form_state->getValue('count'); + $regcode = $form_state->getValue('regcode'); + if (empty($count) && $form_state->getValue('operation') === 'delete_uses') { $form_state->setErrorByName('count', $this->t('Count of items should not be empty')); } + if (!empty($regcode)) { + $code = regcode_load_single($regcode); + if ($code->maxuses < $count) { + $form_state->setErrorByName('count', $this->t('Count of items should not be bigger than max usage')); + } + } } /**