mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 09:44:38 +02:00
Add PR #191 - Use step attribute = precision in float inputfield if html5 number
This commit is contained in:
@@ -96,10 +96,7 @@ class FieldtypeDecimal extends Fieldtype {
|
||||
public function getInputfield(Page $page, Field $field) {
|
||||
/** @var InputfieldFloat $inputfield */
|
||||
$inputfield = $this->wire()->modules->get('InputfieldFloat');
|
||||
$precision = (int) $field->get('precision');
|
||||
if($field->get('inputType') === 'number' && $precision > 0) {
|
||||
$inputfield->attr('step', '.' . ($precision > 1 ? str_repeat('0', $precision - 1) : '') . '1');
|
||||
}
|
||||
$inputfield->set('precision', $field->get('precision'));
|
||||
return $inputfield;
|
||||
}
|
||||
|
||||
|
@@ -112,6 +112,10 @@ class InputfieldFloat extends InputfieldInteger {
|
||||
$attributes['value'] = $this->localeConvertValue($value);
|
||||
}
|
||||
}
|
||||
$precision = (int) $this->precision;
|
||||
if($precision > 0 && (empty($attributes['step']) || $attributes['step'] === 'any')) {
|
||||
$attributes['step'] = '.' . ($precision > 1 ? str_repeat('0', $precision - 1) : '') . '1';
|
||||
}
|
||||
}
|
||||
return parent::getAttributesString($attributes);
|
||||
}
|
||||
|
Reference in New Issue
Block a user