Jump to content

helpers form width & height help


Recommended Posts

Posted

If I was to make a setting for width & height like below

$ImageSize = ( isset( \IPS\Settings::i()->MyImageSize ) ) ? explode( 'x', \IPS\Settings::i()->MyImageSize ) : array( 75, 75 );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'MyImageSize', $ImageSize, TRUE, array( 'resizableDiv' => TRUE ), NULL, NULL, NULL, 'MyImageSize' ) );

How would I implement that into a css file?

Posted

CSS files parse template plugins, so you should be able to do something like

{{$size = explode( 'x', \IPS\Settings::i()->mysetting );}}
.class {
	width: {$size[0]}px;
	height: {$size[1]}px;
}

 

Posted
56 minutes ago, bfarber said:

CSS files parse template plugins, so you should be able to do something like


{{$size = explode( 'x', \IPS\Settings::i()->mysetting );}}
.class {
	width: {$size[0]}px;
	height: {$size[1]}px;
}

 

I got a new problem, when i create the settings in the settings.php it shows fine in the plugin settings, but when I once I add the settings key to the settings in developer center it throws this error when opening the plugin settings if I remove the key the error is gone and it shows, (But obviously it won't save without the key)

Whoops\Exception\ErrorException Object
(
    [message:protected] => Undefined offset: 1
    [string:Exception:private] => 
    [code:protected] => 8
    [file:protected] => /system/Helpers/Form/WidthHeight.php
    [line:protected] => 73
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /system/Helpers/Form/WidthHeight.php
                    [line] => 73
                    [function] => handleError
                    [class] => Whoops\Run
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 8
                            [1] => Undefined offset: 1
                            [2] => /system/Helpers/Form/WidthHeight.php
                            [3] => 73
                            [4] => Array
                                (
                                )

                        )

                )

I have left the default value blank and I have also put 75x75, It did open once but from then on that error shows

Posted

That error would be occurring if the default value you pass to the form helper was not an array with two elements (width and height). The developer center has no knowledge of what type of form helper you use for a given setting key, so I presume the error is occurring inside the settings.php file related to your custom code (the stack trace doesn't show far enough back to know where the error is happening).

Posted
11 minutes ago, bfarber said:

That error would be occurring if the default value you pass to the form helper was not an array with two elements (width and height). The developer center has no knowledge of what type of form helper you use for a given setting key, so I presume the error is occurring inside the settings.php file related to your custom code (the stack trace doesn't show far enough back to know where the error is happening).

the actual error is about 10k words and more this is a big plugin with a lot of settings and code so the arrays are long, this is the error log for the actual setting

[euip_AvatarSizetest] => IPS\Helpers\Form\WidthHeight Object
                                                        (
                                                            [defaultOptions:protected] => Array
                                                                (
                                                                    [unlimited] => 
                                                                    [image] => 
                                                                    [resizableDiv] => 1
                                                                )

                                                            [_name:protected] => euip_AvatarSizetest
                                                            [label] => 
                                                            [description] => 
                                                            [defaultValue] => Array
                                                                (
                                                                    [0] => 119,128
                                                                )

                                                            [value] => Array
                                                                (
                                                                    [0] => 119,128
                                                                )

                                                            [unformatted] => 
                                                            [required] => 1
                                                            [appearRequired] => 1
                                                            [options] => Array
                                                                (
                                                                    [unlimited] => 
                                                                    [image] => 
                                                                    [resizableDiv] => 1
                                                                )

                                                            [customValidationCode:protected] => 
                                                            [prefix] => 
                                                            [suffix] => 
                                                            [htmlId] => euip_AvatarSizetest
                                                            [error] => 
                                                            [reloadForm] => 
                                                            [warningBox] => 
                                                            [valueSet] => 
                                                        )

if I delete the setting key then create it again it will work but as soon as I change the size and save it then it will throw the error again the settings code is below

$ImageSize = ( isset( \IPS\Settings::i()->euip_AvatarSizetest ) ) ? explode( 'x', \IPS\Settings::i()->euip_AvatarSizetest ) : array( 75, 75 );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'euip_AvatarSizetest', $ImageSize, TRUE, array( 'resizableDiv' => TRUE ), NULL, NULL, NULL, 'euip_AvatarSizetest' ) );

 

Posted

You are passing the value as a comma separated string instead of as an array

[defaultValue] => Array
                                                                (
                                                                    [0] => 119,128
                                                                )

Presumably this is because a value exists in the database for the setting of "119,128", however you are exploding on 'x'

explode( 'x', \IPS\Settings::i()->euip_AvatarSizetest )

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...