Is it possible to add 'Show/hide div' in the admin areas array hook

Started by Pipke, February 25, 2015, 03:44:19 PM

Previous topic - Next topic

Pipke

Show or Hide a div if checkbox is selected
In this array
$config_vars[] = array('select', ...the code here then i guess, if it can be done or somewhere else
);


Demo HERE
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Yes, the admin part of SMF offers a lot of hidden goodies, one of them is the ability to set JavaScript code to an specific field, I cannot remember exactly how since its been a long time since the last time I used something like that but it is indeed possible. Check Sources/ManageServer.php::prepareDBSettingContext() thats where $config_vars gets handled to be saved to the DB and it has all the possible keys $config_vars can use.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Thx for the fast reply, ill take a look at what you sugested.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Pipke

Got it working, found the code in ManagePaid.php


// These are all the default settings.
   $config_vars = array(
         array('select', 'paid_email', array(0 => $txt['paid_email_no'], 1 => $txt['paid_email_error'], 2 => $txt['paid_email_all']), 'subtext' => $txt['paid_email_desc']),
         array('text', 'paid_email_to', 'subtext' => $txt['paid_email_to_desc'], 'size' => 60),
      '',
         'dummy_currency' => array('select', 'paid_currency', array('usd' => $txt['usd'], 'eur' => $txt['eur'], 'gbp' => $txt['gbp'], 'other' => $txt['other']), 'javascript' => 'onchange="toggleOther();"'),
         array('text', 'paid_currency_code', 'subtext' => $txt['paid_currency_code_desc'], 'size' => 5, 'force_div_id' => 'custom_currency_code_div'),
         array('text', 'paid_currency_symbol', 'subtext' => $txt['paid_currency_symbol_desc'], 'size' => 8, 'force_div_id' => 'custom_currency_symbol_div'),
         array('check', 'paidsubs_test', 'subtext' => $txt['paidsubs_test_desc'], 'onclick' => 'return document.getElementById(\'paidsubs_test\').checked ? confirm(\'' . $txt['paidsubs_test_confirm'] . '\') : true;'),
   );


and we need this also, the javascript

// We want javascript for our currency options.
    $context['settings_insert_below'] = '
        <script type="text/javascript"><!-- // --><![CDATA[
            function toggleOther()
            {
                var otherOn = document.getElementById("paid_currency").value == \'other\';
                var currencydd = document.getElementById("custom_currency_code_div_dd");

                if (otherOn)
                {
                    document.getElementById("custom_currency_code_div").style.display = "";
                    document.getElementById("custom_currency_symbol_div").style.display = "";

                    if (currencydd)
                    {
                        document.getElementById("custom_currency_code_div_dd").style.display = "";
                        document.getElementById("custom_currency_symbol_div_dd").style.display = "";
                    }
                }
                else
                {
                    document.getElementById("custom_currency_code_div").style.display = "none";
                    document.getElementById("custom_currency_symbol_div").style.display = "none";

                    if (currencydd)
                    {
                        document.getElementById("custom_currency_symbol_div_dd").style.display = "none";
                        document.getElementById("custom_currency_code_div_dd").style.display = "none";
                    }
                }
            }
            toggleOther();
        // ]]></script>';
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Advertisement: