Number.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. class Number extends Text
  4. {
  5. protected $view = 'admin::form.number';
  6. protected $options = [
  7. 'upClass' => 'primary shadow-0',
  8. 'downClass' => 'light shadow-0',
  9. 'center' => true
  10. ];
  11. /**
  12. * Set min value of number field.
  13. *
  14. * @param int $value
  15. *
  16. * @return $this
  17. */
  18. public function min($value)
  19. {
  20. $this->attribute('min', $value);
  21. return $this;
  22. }
  23. /**
  24. * Set max value of number field.
  25. *
  26. * @param int $value
  27. *
  28. * @return $this
  29. */
  30. public function max($value)
  31. {
  32. $this->attribute('max', $value);
  33. return $this;
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. protected function prepareInputValue($value)
  39. {
  40. return empty($value) ? 0 : $value;
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function value($value = null)
  46. {
  47. if (is_null($value)) {
  48. return (int) parent::value();
  49. }
  50. return parent::value($value);
  51. }
  52. public function render()
  53. {
  54. $this->defaultAttribute('style', 'width: 140px;flex:none');
  55. $this->prepend('');
  56. return parent::render();
  57. }
  58. }