Skip to content
Discussion options

You must be logged in to vote

You're right about the relationship between decimals and the step attribute in number fields. The HTML5 validation for number inputs requires the step attribute to match the decimal precision you want to allow.

In Backpack, when using a number field, you need to explicitly set the attributes with the appropriate step value to allow decimal inputs. The decimals parameter alone won't configure the HTML input validation correctly.

Your implementation is correct:

CRUD::addField([
    'name' => 'usd',
    'tab' => 'Prices',
    'decimals' => 3,
    'attributes' => [
        'step' => "0.001",
    ],
    'label' => 'Price in USD',
    'type' => 'number',
    'prefix' => '$',
    'suffix' => ' USD'

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jakimoff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant