Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/lib/form/ -> float.php (source)

Float type form element Contains HTML class for a float type element

Copyright: 2019 Shamim Rezaie <shamim@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 193 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

MoodleQuickForm_float:: (8 methods):
  __construct()
  onQuickFormEvent()
  validateSubmitValue()
  setValue()
  getValue()
  exportValue()
  _getPersistantData()
  format_float()


Class: MoodleQuickForm_float  - X-Ref

Float type form element.

This is preferred over the text element when working with float numbers, and takes care of the fact that different languages
may use different symbols as the decimal separator.
Using this element, submitted float numbers will be automatically translated from the localised format into the computer format,
and vice versa when they are being displayed.

__construct($elementName = null, $elementLabel = null, $attributes = null)   X-Ref
MoodleQuickForm_float constructor.

param: string $elementName (optional) name of the float field
param: string $elementLabel (optional) float field label
param: string $attributes (optional) Either a typical HTML attribute string or an associative array

onQuickFormEvent($event, $arg, &$caller)   X-Ref
Called by HTML_QuickForm whenever form event is made on this element.

param: string $event Name of event
param: mixed $arg event arguments
param: object $caller calling object
return: bool

validateSubmitValue($value)   X-Ref
Checks that the submitted value is a valid float number.

param: string $value The localised float number that is submitted.
return: string|null Validation error message or null.

setValue($value)   X-Ref
Sets the value of the form element.

param: string $value Default value of the form element

getValue()   X-Ref
Returns the value of the form element.

return: false|float

exportValue(&$submitValues, $assoc = false)   X-Ref
Returns a 'safe' element's value.

param: array   $submitValues array of submitted values to search
param: bool    $assoc whether to return the value as associative array
return: mixed

_getPersistantData()   X-Ref
Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on.

return: string

format_float($value)   X-Ref
Given a float, prints it nicely.
This function reserves the number of decimal places.

param: float|null $value The float number to format
return: string Localised float