Tuesday 01 July 2008 7:14:25 pm
Thank you Michael, but something tell me that it is not just a matter of new type. In fact, as I saw in ezselection.tpl file, "selected_id_array" variable is managed as an array type variable. So the POST variable is an array, we get an array, we send an array etc... (see name="{$attribute_base}_ezselect_selected_array_{$attribute.id}[]") But in ezselectiontype.php file, to check if the variable is valid or not, we manage this array as a string (see $data == "")
So I would say that there is a mistake in ezselectiontype.php file and that the variable has to be managed as in ezcountrytype.php (see count( $data ) > 0 and $data[0] != ''). By this way, I will be able to change just ezselection.tpl file to handle empty options like :
{if $Options.item.name|compare("")}
<option value="" {if $selected_id_array|count()|eq(0)}selected="selected"{/if}>{$Options.item.name|wash( xhtml )}</option>
{else}
<option value="{$Options.item.id}" {section show=$selected_id_array|contains( $Options.item.id )}selected="selected"{/section}>{$Options.item.name|wash( xhtml )}</option>
{/if}
Am I totally wrong ? <b>ezselection.tpl</b>
{* DO NOT EDIT THIS FILE! Use an override template instead. *}
{default attribute_base=ContentObjectAttribute}
{let selected_id_array=cond( is_set( $#collection_attributes[$attribute.id] ), $#collection_attributes[$attribute.id].content, $attribute.content )}
{* Always set the .._selected_array_.. variable, this circumvents the problem when nothing is selected. *}
<input type=hidden name="{$attribute_base}_ezselect_selected_array_{$attribute.id}" value="">
<select name="{$attribute_base}_ezselect_selected_array_{$attribute.id}[]" {section show=$attribute.class_content.is_multiselect}multiple{/section}>
{section var=Options loop=$attribute.class_content.options}
<option value="{$Options.item.id}" {section show=$selected_id_array|contains( $Options.item.id )}selected="selected"{/section}>{$Options.item.name|wash( xhtml )}</option>
{/section}
</select>
{/let}
{/default}
<b>ezselectiontype.php</b>
function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
if ( $http->hasPostVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
{
$data = $http->postVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) );
if ( $data == "" && $contentObjectAttribute->validateIsRequired() )
{
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'Input required.' ) );
return eZInputValidator::STATE_INVALID;
}
else
{
return eZInputValidator::STATE_ACCEPTED;
}
}
else
{
return eZInputValidator::STATE_INVALID;
}
}
<b>ezcountrytype.php</b>
function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
if ( !$contentObjectAttribute->validateIsRequired() )
return eZInputValidator::STATE_ACCEPTED;
if ( $http->hasPostVariable( $base . '_country_' . $contentObjectAttribute->attribute( 'id' ) ) )
{
$data = $http->postVariable( $base . '_country_' . $contentObjectAttribute->attribute( 'id' ) );
if ( count( $data ) > 0 and $data[0] != '' )
return eZInputValidator::STATE_ACCEPTED;
}
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
'Input required.' ) );
return eZInputValidator::STATE_INVALID;
}
|