1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

Add PR #191 - Use step attribute = precision in float inputfield if html5 number

This commit is contained in:
pine3ree
2021-06-01 10:33:02 -04:00
committed by Ryan Cramer
parent 73b82462fc
commit bb5d846b04
2 changed files with 5 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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);
}