Default Value for Dropdowns

14 years 1 month ago #125147 by slinky
Default Value for Dropdowns was created by slinky
I'm trying to create a "please select" default value for dropdown fields that are required. CB unfortunately selects the first item on a list as the required value, e.g. if it is states, Alabama is first on the list. That one is preselected on "required" field. I would think it better if the default was "please select" which I typed into default value. CB ignores this text and uses the first value available. Most users don't realize that field isn't filled in and go past it.

Wondering if anyone else has solved this.

Please Log in to join the conversation.

14 years 1 month ago #125148 by slinky
Replied by slinky on topic Re:Default Value for Dropdowns
Just found this although it's from almost a year ago and claims a fix may have been made:

www.joomlapolis.com/component/option,com_joomlaboard/Itemid,38/func,view/id,100392/catid,99/limit,6/limitstart,6/

Not sure if hacking is a good idea right now. Wondering if there is an official solution that solves this for all dropdowns. If not required you get a blank space. If it is required, first value is automatically selected.

Please Log in to join the conversation.

14 years 1 month ago #125150 by slinky
Replied by slinky on topic Re:Default Value for Dropdowns
The Solution as per Joomlapoplis (not added into latest version released) and parts to remove commented out:



in administrator/components/com_comprofiler/comprofiler.class.php
[code:1] function selectList( &$arr, $tag_name, $tag_attribs, $key, $text, $selected, $required = 0, $htmlspecialcharText = true ) {

reset( $arr );

$id_name = moscomprofilerHTML::htmlId( $tag_name );

$html = "\n"

. '<select name="' . htmlspecialchars( $tag_name ) . '" id="' . htmlspecialchars( $id_name ) . '" ' . $tag_attribs . '>';


/* $addBlank = ( ( ! $required ) && ! ( isset( $arr[0] ) && $arr[0]->$key == '' ) ); */

$addBlank = ( ( ( ! $required ) || ( is_array( $selected ) ? ( count( $selected ) == 0 ) : ( $selected == '' ) ) ) && ! ( isset( $arr[0] ) && $arr[0]->$key == '' ) );


if ( $addBlank ) {

$html .= "\n\t<option value=\"\"> </option>";

}

[/code:1]


In the same directory, plugin.class.php
[code:1] function _explodeCBvaluesToObj( $value ) {
if ( ! is_array( $value ) ) {
/* $value = explode( '|*|', $value ); */

if ( ( $value === '' ) || is_null( $value ) ) {
$value = array();
} else {
$value = explode( '|*|', $value );
}


}
$objArr = array();
foreach( $value as $k => $kv ) {
$objArr[$k]->value = $kv;
$objArr[$k]->text = $kv;
}
return $objArr;
}
function _explodeCBvalues( $value ) {
return explode( '|*|', $value );
}
[/code:1]

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.170 seconds

Facebook Twitter LinkedIn