Skip to content

Number field

Loïc Antignac edited this page May 24, 2022 · 8 revisions

image

By default, number field only requests the following informations:

[
	'slug'   => 'nb_max_photos',
	'type'   => 'number',
	'labels' => [
		'label' => 'nb_max_photos_label',
		'help'  => 'nb_max_photos_help',
	],
],

The labels key contains the keys for retrieving the labels from the labels array at the root of the entity declaration. Eg:

$declarations[] = [
	'entity'   => 'Webaxones\Core\Option\SettingGroup',
		'labels'   => [
			'nb_max_photos_label'    => __( 'Maximum number of photos', 'webaxones-content' ),
			'nb_max_photos_help'     => __( 'Maximum number of photos to display on the gallery', 'webaxones-content' ),
		],

But it is also possible to format the number field with an additional key called args which takes an array of the optional arguments that an HTML 5 input type number can support.

Example:

[
	'slug'   => 'nb_max_photos',
	'type'   => 'number',
	'labels' => [
		'label' => 'nb_max_photos_label',
		'help'  => 'nb_max_photos_help',
	],
	'args'   => [
		'value'       => '0',
		'step'        => '1',
		'min'         => '0',
		'max'         => '100',
		'required'    => true,
	],
],
Clone this wiki locally