-
Notifications
You must be signed in to change notification settings - Fork 36
Multiselect #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Multiselect #65
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,11 @@ | |
| $custom_attribute_types = array() | ||
| $custom_attribute_names = array() | ||
| $custom_attribute_selections = array() | ||
| $custom_attribute_value = '' | ||
| $custom_attribute_values = array() | ||
| $custom_attribute_default = '' | ||
| $custom_attribute_multiselect_setting = false() | ||
| $custom_attribute_multiselect_value = false() | ||
| $loop_count = 0} | ||
| {if ezini_hasvariable( $block.type, 'CustomAttributes', 'block.ini' )} | ||
| {set $custom_attributes = ezini( $block.type, 'CustomAttributes', 'block.ini' )} | ||
|
|
@@ -129,12 +134,56 @@ | |
| <input id="block-custom_attribute-{$block_id}-{$loop_count}" class="textfield block-control" type="text" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]" value="{$block.custom_attributes[$custom_attrib]|wash()}" /> | ||
| {/case} | ||
| {case match = 'select'} | ||
| {set $custom_attribute_selections = ezini( $block.type, concat( 'CustomAttributeSelection_', $custom_attrib ), 'block.ini' )} | ||
| <select id="block-custom_attribute-{$block_id}-{$loop_count}" class="block-control" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]"> | ||
| {foreach $custom_attribute_selections as $selection_value => $selection_name} | ||
| <option value="{$selection_value|wash()}"{if eq( $block.custom_attributes[$custom_attrib], $selection_value )} selected="selected"{/if} />{$selection_name|wash()}</option> | ||
| {/foreach} | ||
| </select> | ||
| {set $custom_attribute_selections = ezini( $block.type, concat( 'CustomAttributeSelection_', $custom_attrib ),'block.ini' )} | ||
|
|
||
| {* Check if there is a default value for the select *} | ||
| {if ezini_hasvariable( $block.type, concat( 'CustomAttributeSelectionDefault_', $custom_attrib ), 'block.ini' )} | ||
| {set $custom_attribute_default = ezini( $block.type, concat( 'CustomAttributeSelectionDefault_', $custom_attrib ), 'block.ini' )} | ||
| {else} | ||
| {set $custom_attribute_default = ''} | ||
| {/if} | ||
|
|
||
| {* Check if there is a value set for the custom attribute - empty is assumed to be no value *} | ||
| {if $block.custom_attributes[$custom_attrib]|ne( '' )} | ||
| {set $custom_attribute_value = $block.custom_attributes[$custom_attrib]} | ||
| {else} | ||
| {set $custom_attribute_value = $custom_attribute_default} | ||
| {/if} | ||
|
|
||
| {* Test for multiselect option *} | ||
| {set $custom_attribute_multiselect_setting = ezini_hasvariable( $block.type, concat( 'CustomAttributeMultipleSelection_', $custom_attrib ), 'block.ini' )} | ||
| {* If multiselect select option is set, use the value *} | ||
| {if $custom_attribute_multiselect_setting} | ||
| {* Test against common settings which may be used *} | ||
| {set $custom_attribute_multiselect_value = array('1',1,'true',true())|contains(ezini( $block.type, concat( 'CustomAttributeMultipleSelection_', $custom_attrib ), 'block.ini' ))} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should standardize a value. I would suggest "enabled". |
||
| {else} | ||
| {* Default value is false - single select *} | ||
| {set $custom_attribute_multiselect_value = false()} | ||
| {/if} | ||
|
|
||
| {* Set custom_attribute_values based on the multiselect setting value *} | ||
| {if $custom_attribute_multiselect_value} | ||
| {set $custom_attribute_values = $custom_attribute_value|explode(',')} | ||
| {else} | ||
| {set $custom_attribute_values = array( $custom_attribute_value )} | ||
| {/if} | ||
|
|
||
| {def $i_selected = ''} | ||
| <select id="block-custom_attribute-{$block_id}-{$loop_count}" class="block-control" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]{if $custom_attribute_multiselect_value}[]" multiple="multiple" size="{min($custom_attribute_selections|count(), 6)}"{else}" size="1"{/if}> | ||
| {foreach $custom_attribute_selections as $selection_value => $selection_name} | ||
|
|
||
| {* mark option as selected *} | ||
| {set $i_selected = ''} | ||
| {foreach $custom_attribute_values as $value} | ||
| {if eq( $value|trim(), $selection_value|trim() )} | ||
| {set $i_selected = 'selected="selected"'} | ||
| {break} | ||
| {/if} | ||
| {/foreach} | ||
|
|
||
| <option value="{$selection_value|trim()|wash()}" {$i_selected}>{$selection_name|wash()}</option> | ||
| {/foreach} | ||
| </select> | ||
| {/case} | ||
| {case} | ||
| <input id="block-custom_attribute-{$block_id}-{$loop_count}" class="textfield block-control" type="text" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]" value="{$block.custom_attributes[$custom_attrib]|wash()}" /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,10 @@ RootSubtree=1 | |
| # CustomAttributeSelection_color[] | ||
| # CustomAttributeSelection_color[blue]=Blue | ||
| # CustomAttributeSelection_color[green]=Green | ||
| # Set the default | ||
| # CustomAttributeSelectionDefault_color=green | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can multiple defaults be selected? If so, this should be documented. |
||
| # Allow multiple items to be selected | ||
| # CustomAttributeMultipleSelection_color[]=1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be an array? |
||
| # UseBrowseMode[node_id]=true | ||
| # Optional: set the browse mode start node for a custom attribute | ||
| # CustomAttributeStartBrowseNode[node_id]=<node_id> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the user would want to select no value and we only want to set a default on the first load? (I'm not sure what the solution would be in that case and/or whether that's a valid use case, but it's something to consider.)