2019-10-15 09:33:03 +08:00

84 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* FormBuilder表单生成器
* Author: xaboy
* Github: https://github.com/xaboy/form-builder
*/
namespace FormBuilder\components;
use FormBuilder\FormComponentDriver;
/**
* 数字输入框组件
* Class InputNumber
*
* @package FormBuilder\components
* @method $this max(float $max) 最大值
* @method $this min(float $min) 最小值
* @method $this step(float $step) 每次改变的步伐,可以是小数
* @method $this size(String $size) 输入框尺寸可选值为large、small、default或者不填
* @method $this disabled(Boolean $bool) 设置禁用状态默认为false
* @method $this placeholder(String $placeholder) 占位文本
* @method $this readonly(Boolean $bool) 是否设置为只读默认为false
* @method $this editable(Boolean $bool) 是否可编辑默认为true
* @method $this precision(int $precision) 数值精度
*/
class InputNumber extends FormComponentDriver
{
/**
* @var string
*/
protected $name = 'inputNumber';
/**
* @var array
*/
protected static $propsRule = [
'max' => 'float',
'min' => 'float',
'step' => 'float',
'disabled' => 'boolean',
'size' => 'string',
'placeholder' => 'string',
'readonly' => 'boolean',
'editable' => 'boolean',
'precision' => 'int',
];
/**
*
*/
protected function init()
{
$this->placeholder($this->getPlaceHolder());
}
protected function getPlaceHolder($pre = '请输入')
{
return parent::getPlaceHolder($pre);
}
public function getValidateHandler()
{
return Validate::num(Validate::TRIGGER_BLUR);
}
/**
* @return array
*/
public function build()
{
return [
'type' => $this->name,
'field' => $this->field,
'title' => $this->title,
'value' => $this->value === '' ? '' : (float)$this->value,
'props' => (object)$this->props,
'validate' => $this->validate,
'col' => $this->col
];
}
}