InputNumber.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * FormBuilder表单生成器
  4. * Author: xaboy
  5. * Github: https://github.com/xaboy/form-builder
  6. */
  7. namespace FormBuilder\components;
  8. use FormBuilder\FormComponentDriver;
  9. /**
  10. * 数字输入框组件
  11. * Class InputNumber
  12. * @package FormBuilder\components
  13. * @method $this max(float $max) 最大值
  14. * @method $this min(float $min) 最小值
  15. * @method $this step(float $step) 每次改变的步伐,可以是小数
  16. * @method $this size(String $size) 输入框尺寸,可选值为large、small、default或者不填
  17. * @method $this disabled(Boolean $bool) 设置禁用状态,默认为false
  18. * @method $this placeholder(String $placeholder) 占位文本
  19. * @method $this readonly(Boolean $bool) 是否设置为只读,默认为false
  20. * @method $this editable(Boolean $bool) 是否可编辑,默认为true
  21. * @method $this precision(int $precision) 数值精度
  22. */
  23. class InputNumber extends FormComponentDriver
  24. {
  25. /**
  26. * @var string
  27. */
  28. protected $name = 'inputNumber';
  29. /**
  30. * @var array
  31. */
  32. protected static $propsRule = [
  33. 'max' => 'float',
  34. 'min' => 'float',
  35. 'step' => 'float',
  36. 'disabled' => 'boolean',
  37. 'size' => 'string',
  38. 'placeholder' => 'string',
  39. 'readonly' => 'boolean',
  40. 'editable' => 'boolean',
  41. 'precision' => 'int',
  42. ];
  43. /**
  44. *
  45. */
  46. protected function init()
  47. {
  48. $this->placeholder($this->getPlaceHolder());
  49. }
  50. protected function getPlaceHolder($pre = '请输入')
  51. {
  52. return parent::getPlaceHolder($pre);
  53. }
  54. protected function getValidateHandler()
  55. {
  56. return Validate::num(Validate::TRIGGER_BLUR);
  57. }
  58. /**
  59. * @return array
  60. */
  61. public function build()
  62. {
  63. return [
  64. 'type' => $this->name,
  65. 'field' => $this->field,
  66. 'title' => $this->title,
  67. 'value' => $this->value === '' ? '' : (float)$this->value,
  68. 'props' => (object)$this->props,
  69. 'validate' => $this->validate,
  70. 'col'=>$this->col
  71. ];
  72. }
  73. }