NumberField.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Symfony\Component\Form;
  3. /*
  4. * This file is part of the Symfony framework.
  5. *
  6. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. use Symfony\Component\Form\ValueTransformer\NumberToLocalizedStringTransformer;
  12. /**
  13. * A localized field for entering numbers.
  14. *
  15. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  16. */
  17. class NumberField extends InputField
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function __construct($key, array $options = array())
  23. {
  24. $options['type'] = 'text';
  25. parent::__construct($key, $options);
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. protected function configure()
  31. {
  32. parent::configure();
  33. // default precision is locale specific (usually around 3)
  34. $this->addOption('precision');
  35. $this->addOption('grouping', false);
  36. $this->addOption('rounding-mode', NumberToLocalizedStringTransformer::ROUND_HALFUP);
  37. $this->setValueTransformer(new NumberToLocalizedStringTransformer(array(
  38. 'precision' => $this->getOption('precision'),
  39. 'grouping' => $this->getOption('grouping'),
  40. 'rounding-mode' => $this->getOption('rounding-mode'),
  41. )));
  42. }
  43. }