CMS MADE SIMPLE FORGE

AdvancedContent

 

[#6726] Conditional Disable Field

avatar
Created By: Kenneth Griffith (kendo451)
Date Submitted: 2011-08-01 05:12

Assigned To:
Resolution: Fixed
State: Closed
Summary:
Conditional Disable Field
Detailed Description:
It would be nice to be able to enable/disable certain fields based on the value
of another one.

Example A:

Field 1: 
Checkbox field for "2 columns"
{content block='column_2_enable' type='checkbox' default=0}

Field/Group 2:
If field1 = checked (in Admin) enable
 {content block='col2title' block_group='Column 2' disable='column_2_enable,0'}
 {content block='col2text' block_group='Column 2'}

Example B:
Field 1:
{content block='layout' block_type='dropdown' values='1col|2col|3col'}

Field/Group 2:
{content block='col2title' block_group='Column 2'
enable='layout,2col|layout,3col'}
{content block='col2text' block_group='Column 2'
enable='layout,2col|layout,3col'}

The second example allows the fields to be enabled if $layout == '2col' or if
$layout == '3col'

Obviously this would use JQERY on the backend to disable/enable form fields, as
it makes no difference on the front-end.

History

Comments
avatar
Date: 2011-08-04 06:30
Posted By: Georg Busch (nan)

Dear Kenneth,

thanks for your suggestions.
This is really a very interesting idea.
So i would just need to add a new param to define what content block will
controll what other block or will be controlled by what block.
Thing is, defining a block in a frontend template that actually is only for the
backend just seems not right to me. You will have some useless overhead in your
frontend template.

Need to think about it.
      
avatar
Date: 2011-09-09 16:41
Posted By: Georg Busch (nan)

Dear Kenneth,

i recently found a solution without modifying anything in the module.
All you need to do is to use the description parameter to insert some javascript
code that toggles whatever you want.
Here is a simple example...

1st create a UDT named 'change_input':

# code #

echo "
<script type=\"text/javascript\">
jQuery(document).ready(function() {
    jQuery('#". $params['control_who'] ."').change(function() { 
        if(this.checked) {
            jQuery('#". $params['control_what'] ."').removeAttr('checked');
if( jQuery('#". $params['control_what'] ."_wrapper').css('display')
!= 'none') {
                jQuery('#toggle-". $params['control_what'] ."').click();
            }
        }
        else {
            jQuery('#". $params['control_what'] ."').attr('checked','checked');
if( jQuery('#". $params['control_what'] ."_wrapper').css('display')
== 'none') {
                jQuery('#toggle-". $params['control_what'] ."').click();
            }
            jQuery('#toggle-". $params['control_who'] ."').click();
        }
    });
});
</script>";

# /code #

You need to pass 2 params to this UDT

control_who : the name of the block that controls another
control_what : the name of the block that is controlled


2nd use this UDT as value for the description parameter:

# template #

{content block="Content" block_type='checkbox' label="Enable/Disable the content
in frontend" default="1" description="If enabled it will disable the teasertext
and vise versa. :::change_input control_who='Content'
control_what='Teasertext':::" smarty="true" assign="display_content"}

{content block="Teasertext" block_type='checkbox' label="Enable/Disable the
teasertext in frontend" description="If enabled it will disable the content and
vise versa. :::change_input control_who='Teasertext' control_what='Content':::"
smarty="true" assign="display_teasertext"}

# /template #



All inputs of the contentblocks will have the id of the block-param.
All blocks are wrapped in a div with the id '[block id]_wrapper'
All blocks of a block_group are wrapped in a div with an id that consists of the
'[page_tab]_[block_tab]_[block_group]'
All triggers to toggle blocks have the id 'toggle-[block id]'
And last not least all triggers to toggle block_groups have the id
'toggle-[page_tab]_[block_tab]_[block_group]'
So you can target every element using javascript that is just inserted in the
description of a block.



Hope this helps.
Cheers.
      
Updates

Updated: 2011-10-25 15:43
resolution_id: 10 => 7
state: Open => Closed

Updated: 2011-09-09 16:41
resolution_id: 5 => 10

Updated: 2011-08-04 06:30
resolution_id: => 5