Example #1
0
 private function addDiscountPercentControl()
 {
     $errorMessage = 'Discount percent must be number between 0 and 100.';
     $control = $this->addText('discountPercent', 'Discount percent');
     $control->setType('number')->setAttribute('step', 'any')->setDefaultValue(0)->addRule(self::FLOAT, $errorMessage)->addRule(function (TextInput $input) {
         return $input->getValue() >= 0 && $input->getValue() < 100;
     }, $errorMessage);
     if ($this->editedProduct !== null) {
         $control->setDefaultValue($this->editedProduct->getDiscountPercent());
     }
 }