Skip to content
Snippets Groups Projects

Issue #3418994 Support min/max values in price render element

1 file
+ 6
1
Compare changes
  • Side-by-side
  • Inline
@@ -16,6 +16,8 @@ use Drupal\Core\Render\Element\FormElement;
* '#title' => $this->t('Amount'),
* '#default_value' => ['number' => '99.99', 'currency_code' => 'USD'],
* '#allow_negative' => FALSE,
* '#min' => 10,
* '#max' => 100,
* '#size' => 60,
* '#maxlength' => 128,
* '#required' => TRUE,
@@ -42,6 +44,8 @@ class Price extends FormElement {
'#maxlength' => 128,
'#default_value' => NULL,
'#allow_negative' => FALSE,
'#min' => NULL,
'#max' => NULL,
'#attached' => [
'library' => ['commerce_price/admin'],
],
@@ -119,7 +123,8 @@ class Price extends FormElement {
'#size' => $element['#size'],
'#maxlength' => $element['#maxlength'],
'#min_fraction_digits' => min($fraction_digits),
'#min' => $element['#allow_negative'] ? NULL : 0,
'#min' => $element['#min'] ?? ($element['#allow_negative'] ? NULL : 0),
'#max' => $element['#max'],
'#description' => t('Format: @format', ['@format' => $number_formatter->format('9.99')]),
];
if (isset($element['#ajax'])) {
Loading