此 number 字段渲染一个单行文本框,只接受数字输入。
your_age:
label: Your Age
type: number以下 字段属性 受支持且常用。
| Property | Description |
|---|---|
| label | a name when displaying the form field to the user. |
| default | specifies a default string value, optional. |
| comment | places a descriptive comment below the field. |
| min | the client-side minimum value, default null. |
| max | the client-side maximum value, default null. |
| step | the client-side step increment, default any. |
您可以使用 min 和 max 属性来根据最小值和最大值约束输入。以下将只接受 1 到 100 之间的输入。
your_age:
label: Your Age
type: number
min: 1
max: 100使用 step 属性来控制数字可以增加或减少的增量,该值默认为 任意值。
your_age:
label: Your Age
type: number
step: 10如果您想在保存时于服务器端验证此字段,以确保其为数字。 当使用定制字段时,请使用 validation 属性。
your_age:
label: Your Age
type: number
validation: numeric在使用模型时,使用模型上的 $rules 属性,如下所示。
public $rules = [
'your_age' => ['numeric'],
];有关模型验证的更多信息,请访问 验证服务文章。