SOLVED: The default argument for Number Control doesn't seem to do anything

Bricks Version: 1.4

I’m having a bit of trouble getting the default to actually be recognized. One would assume that setting the default to 1 in the following example would mean that if left blank by the user, the set_attribute in the render would utilize the default. Here’s an example:

Under set_controls():

$this->controls['speed'] = [
	'tab'         => 'content',
	'label'       => esc_html__( 'Animation speed', 'bricks' ),
	'type'        => 'number',
	'step' => '0.1',
	'inline' => true,
	'default' => 1,
	'reset' => true,
];

Under render():

$this->set_attribute( '_root', 'speed', $settings['speed'] );

Result:

<div speed></div>
  • Note: I’ve tried both as a string and an integer.

Try this

$speed = isset( $settings['speed'] ) ? $settings['speed'] : 1;
$this->set_attribute( '_root', 'speed', $speed );

Also you will add the “unitless” param into the control array

'unitless' => true

Hey thanks!

That’s actually what I’m doing already to get around this.

But the docs say default is a universal control argument, so either:

  1. It’s a bug and should be fixed
  2. The docs are wrong and default is not universal
  3. My understanding of default is incorrect (true, see below)

And thanks, unitless was only found on two element control docs so I didn’t even know about it. Although it seems to work either way for me. So I’m not sure what the benefit is? :slightly_smiling_face:

Edit: I suppose my understanding of what “default” means could be skewed as well.

Yup, it turns out my understanding of default was incorrect. Default is just what is set automatically when creating a new element. If you clear it, it will be empty when accessing the settings object.

I feel it would be handy if the default was also passed along in the settings object, but I guess this isn’t exactly a bug and is more preferential.

default

Hey Curtis,
I’ve only skimmed the thread now… but if I have understood correctly it is not a bug and can be marked as solved?

Best regards,
timmse

1 Like