Skip to content

Commit

Permalink
GetDKAN#4068: Provide number widget
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-korn committed Nov 27, 2023
1 parent 496976a commit 7de1b65
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/json_form_widget/src/WidgetRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function getWidgets() {
'date' => 'handleDateElement',
'flexible_datetime' => 'handleDatetimeElement',
'date_range' => 'handleDateRangeElement',
'number' => 'handleNumberElement',
];
}

Expand Down Expand Up @@ -410,4 +411,33 @@ public function handleDateRangeElement($spec, array $element) {
return $element;
}

/**
* Helper function for getting a number element.
*
* @param mixed $spec
* Object with spec for UI options.
* optional specs
* - step
* - min
* - max
* @param array $element
* Element to convert into number.
*
* @return array
* The element configured as number.
*/
public function handleNumberElement($spec, array $element) {
$element['#type'] = 'number';
if (isset($spec->step)) {
$element['#step'] = $spec->step;
}
if (isset($spec->min)) {
$element['#min'] = $spec->min;
}
if (isset($spec->step)) {
$element['#max'] = $spec->max;
}
return $element;
}

}

0 comments on commit 7de1b65

Please sign in to comment.