Skip to content

Text field

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

image

By default, text field only requests the following informations:

[
	'slug'   => 'company_name',
	'type'   => 'text',
	'labels' => [
		'label' => 'company_name_label',
		'help'  => 'company_name_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'   => [
			'company_name_label'    => __( 'Company name', 'webaxones-content' ),
			'company_name_help'     => __( 'Full name of the company', 'webaxones-content' ),
		],

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

Example:

[
	'slug'   => 'company_name',
	'type'   => 'text',
	'labels' => [
		'label' => 'company_name_label',
		'help'  => 'company_name_help',
	],
	'args'   => [
		'maxLength'   => '8',
		'minLength'   => '4',
		'pattern'     => '[a-z]{4,8}',
		'placeholder' => 'username',
		'size'        => '10',
		'required'    => true,
	],
],