themeum / kirki

Extending the customizer

Home Page:https://kirki.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Number" field validation

Qodux opened this issue · comments

commented

Issue description:

Hi there,

I'm using "number" field despite "slider" in my options. I'd like to use the "slider" field if there would be an option to display the input field also where user could enter the value manually there if he doesn't want to drag the slider. This is a suggestion for if you want to take into consideration.

For "number" field, there could be added min / max supported values. This works fine when user click on arrows. But if I manually enter a smaller or bigger value than min / max declared, the options are saved. I suggest a validation here, and if the manually entered values are not in min / max interval then min or max value should be saved. A notice like in "dimension" field for example would be ok. Invalid values in "dimension" field shouldn't be saved but they unfortunately are saved. Probably a small issue.

There would be some issues related to "typography" field which I posted here: #1062

Thanks for your time.

Version used:

(Did you try using the develop branch from github? There's a chance your issue has already been adressed there)
2.3.7

Using theme_mods or options?

theme_mods

Code to reproduce the issue (config + field(s))

Custom_Customizer::add_field( 'Custom_theme', array(
'type' => 'number',
'settings' => 'custom_footer_widgets_areas',
'label' => esc_html__( 'Footer Widgets Areas', 'custom' ),
'description' => esc_html__( 'Select number of Footer Widgets Areas.', 'custom' ),
'section' => 'custom_footer',
'default' => 4,
'choices' => array(
'min' => 0,
'max' => 6,
),
) );

Fixed.
Number controls now do the following:

  • If value is lower than minimum value, min is used.
  • If value is higher than maximum value, max is used.
  • If min = 0 and step = 3 for example and the user enters value 5, it will be rounded to the nearest valid value (in this case 6).

Also notifications were added that can be seen live when the user changes the value to something invalid.

Hi Aristath, do you probably know of sth that causes the min and max not to work in the latest version? I have this code and the min and max does not work. It accepts and saves values which are outside the scope (like 1).

Kirki::add_field( 'controls_kirki', [

	'type'        => 'number',
	'settings'    => 'footer_maxwidth',
	'label'       => wp_kses( 'Maximum width of footer', 'kirki' ),
	'description' => wp_kses( 'The maximum width that the footer can become, for large screens.', 'kirki' ),
	'section'     => 'footer_general_settings',
	'default'     => 1280,
	'priority'    => 30,
	'transport'   => 'auto',
	'choices'     => [
		'min'  => 801,
		'max'  => 5000,
		'step' => 1,
	],
	'output' => [
	[
		'element' => '.footer-column-container',
		'property'    => 'max-width',
		'units' => 'px',
	], ],
] );

It would be great if you could point me to the solution!