Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Form "PercentType" parameter "scale" inconsistency with "NumberType" #35296

Copy link
Copy link
Closed
@emmanuelballery

Description

@emmanuelballery
Issue body actions

Description

Parameter scale of PercentType is a bit confusing when you know how it works for the NumberType one:

  • NumberType will round the submitted value, meaning the model will be rounded too; What's saved and what's shown in the view is identical.
  • PercentType will round the view only, but will save the model with all the decimals sent.

Example

Consider this form:

$form = $this
    ->createFormBuilder()
    ->add('number', NumberType::class, ['scale' => 2])
    ->add('percent', PercentType::class, ['type' => 'integer', 'scale' => 2])
    ->getForm();

Then submit values with more decimals than the scale is set to and dump the model:

image

Something like:

$form->submit(['number' => 1.234, 'percent' => 1.234]);
dump($form->getData());

The NumberType will actually round the model. The PercentType one will ignore this scale and keep every decimals in the model.

image

But the view will then show:

image

Leading to something strange, in my opinion.

Having the same behaviour for both would be great, or changing the name of this parameter in PercentType to make this difference clearer like view_scale for example.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.