This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component
Fabien Potencier 4c78e60ad5 feature #30893 Add "input" option to NumberType (fancyweb, Bernhard Schussek)
This PR was merged into the 4.3-dev branch.

Discussion
----------

Add "input" option to NumberType

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24793
| License       | MIT
| Doc PR        | TODO

This PR replaces #24793 in (partially) fixing how Doctrine's DECIMAL type is handled by the Form component.

Previously, DECIMAL was mapped to the regular NumberType. That confuses Doctrine's change detection, depending on the DB platform.

Examples:

| DB | DB value | Doctrine entity before submit | Form input | Doctrine entity after submit
| --- | --- | --- | --- | ---
| SQLite | 8.000 | '8' | 8 | 8
| SQLite | 8.123 | '8.123' | 8.123 | 8.123
| PostgreSQL | 8.000 | '8.000' | 8 | 8
| PostgreSQL | 8.123 | '8.123' | 8.123 | 8.123

The value in the Doctrine entity changes before and after submit. Hence Doctrine believes an update is necessary.

This PR introduces an `input` option to NumberType (similar to DateType), that can be set to `'number'` (default) or `'string'`. If set to `'string'`, the conversion is as follows:

| DB | DB value | Doctrine entity before submit | Form input | Doctrine entity after submit
| --- | --- | --- | --- | ---
| SQLite | 8.000 | **'8'** | 8 | **'8.000'**
| SQLite | 8.123 | '8.123' | 8.123 | '8.123'
| PostgreSQL | 8.000 | '8.000' | 8 | '8.000'
| PostgreSQL | 8.123 | '8.123' | 8.123 | '8.123'

You see that this does not completely solve this issue for SQLite. However, @Ocramius and I agree that this is something to be fixed by Doctrine, since Doctrine is providing the database abstraction.

That fix should be done in the SqlitePlatform object in Doctrine as part of another PR and should be backwards compatible with the current Doctrine version (i.e. opt in via configuration).

Compared to #24793, this PR does not introduce a new type but instead makes the NumberType more flexible. Also, this PR does not introduce the `force_full_scale` option since that should be solved by Doctrine as described above.

Commits
-------

3f25734647 Added new option "input" to NumberType
fb2b37a8f3 add force_full_scale option to handle all cases
40f25121c3 [DoctrineBridge] Add decimal form type
2019-04-06 20:17:43 +02:00
..
Asset Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
BrowserKit minor #30831 [HttpClient][Contracts] rename "raw_headers" to "response_headers" (nicolas-grekas) 2019-04-02 13:11:42 +02:00
Cache Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Config Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Console Merge branch '4.2' 2019-04-06 18:39:17 +02:00
CssSelector Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Debug feature #28879 [Debug] Mimic __toString php behavior in FlattenException (Deltachaos) 2019-03-31 11:12:58 +02:00
DependencyInjection Merge branch '4.2' 2019-04-06 18:39:17 +02:00
DomCrawler [DomCrawler] Improve Crawler HTML5 parser need detection 2019-04-06 16:52:24 +02:00
Dotenv Merge branch '4.2' 2019-04-06 16:04:46 +02:00
EventDispatcher Merge branch '4.2' 2019-04-06 16:04:46 +02:00
ExpressionLanguage Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Filesystem Handling relative/absolute path 2019-03-27 10:50:42 +01:00
Finder Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Form feature #30893 Add "input" option to NumberType (fancyweb, Bernhard Schussek) 2019-04-06 20:17:43 +02:00
HttpClient minor: remove the logger as it seems uneeded 2019-04-06 11:23:31 +02:00
HttpFoundation Merge branch '4.2' 2019-04-06 16:04:46 +02:00
HttpKernel feature #30906 [symfony/HttpKernel] Throws an error when the generated class name is invalid. (drupol) 2019-04-06 17:52:23 +02:00
Inflector [Inflector] remove "internal" marker from the component 2019-04-01 15:53:46 +02:00
Intl Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Ldap fixed CS 2019-03-31 12:10:11 +02:00
Lock Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Mailer [Mailer] Remove unneeded catch in ping() 2019-03-30 16:56:09 +01:00
Messenger Merge branch '4.2' 2019-04-06 17:38:43 +02:00
Mime [Mime] added BodyRendererInterface 2019-03-27 08:07:59 +01:00
OptionsResolver [OptionsResolver] Add a new method addNormalizer and normalization hierarchy 2019-03-31 13:47:13 +02:00
Process [Process] Added more detail to the exception when the CWD is invalid 2019-04-01 15:29:45 +02:00
PropertyAccess [PropertyAccess] Allow to disable exception on invalid property path when using PropertyAccess::getValue() 2019-04-06 14:47:35 +02:00
PropertyInfo minor #30525 [PropertyInfo] Use a single cache item per method (deviantintegral) 2019-04-03 13:59:42 +02:00
Routing Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Security Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Serializer Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Stopwatch Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Templating Merge branch '4.2' 2019-02-23 16:22:31 +01:00
Translation Merge branch '4.2' 2019-04-06 19:57:49 +02:00
Validator [Validator] Wire NotCompromisedPassword in FrameworkBundle and handle non UTF-8 password 2019-04-06 19:55:53 +02:00
VarDumper [Console] Add dumper 2019-03-24 11:32:26 +01:00
VarExporter Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
WebLink [EventDispatcher] swap arguments of dispatch() to allow registering events by FQCN 2019-03-14 08:32:46 +01:00
Workflow Merge branch '4.2' 2019-04-06 16:04:46 +02:00
Yaml Merge branch '4.2' 2019-04-06 16:04:46 +02:00