8 years ago
2
Topic

I want to do a series of checkbox fields  in a search form.   When the checkbox items are displayed, sometimes the checkbox and its label are separated at the end of a line.  I would like to add wrapping to the input & label  to prevent the break and apply whatever css.  


Where is the code (which file)  that outputs the renderField for checkboxes  on a search form?

I'd like to change it to wrap the input/label with a div+class.

Get a VIP membership
8 years ago
1
Level 1

Until I can change the code (if I can find out where it is) I have constructed an override that accomplishes what I need.  For the benefit of others who might be looking for a similar answer, here is the code and screenshot of the results. 



See next comment for new code.



8 years ago
0
Level 2

I cleaned up the code a bit and added comments to indicate more clearly where changes need to be made if you want to use this override:

/* EDIT -- latest code  (more cleanup) */

<?php
// No Direct Access
defined( '_JEXEC' ) or die;
?>
<?php
/*identify the search for which this is an override ***CHANGE TO MATCH YOUR SEACH LIST NAME */
$searchlistname = "search_by_features";

/*
identify the field names for the checkbox fields and the text we want to use as header text. ***CHANGE THESE TWO LINES TO MATCH YOUR FIELD NAMES AND the TEXT you want to use as Headers for each of the fields
*/
$myfeaturesarray = array("veh_features","veh_navigation_features","veh_audio_features","veh_features__exterior");
$myfeaturesnames = array ("Interior ","Exterior","Audio/Media","Navigation");

/*
set up class styling in your custom css for these two classes Example:

.sebcboxclass {
width:200px;
float:left;
border:1px solid #eee;
}
.sebcboxlabelclass {
display:inline;
}
*/
/*
the contentof the submit button was extracted from the source of the page before overriding
*/
$submitbutton = '<div id="cck1r_button_search"><div id="cck1r_form_button_search"><button type="button" id="button_search" name="button_search" onclick="JCck.Core.submit('."'save'".');return false;"><span></span>Search</button></div></div>';

$arraycount = count($myfeaturesarray);
/*
move through each of our checkbox fields
*/
$x=0;
do {
$myid = $myfeaturesarray[$x];
$thename = $myfeaturesnames[$x];
// get the checkbox values as string of options with || separator then explode it into an array
$myveh_features = $cck->get($myid)->options;
$valuearray = explode("||",$myveh_features);
$vcount=0;
echo '<h3 style="clear;both">'.$thename . '</h3>';
/* Now that we have the options in an array, we will run through them to show the input checkbox and its label. For styling, we enclose those two tags inside a div. */
foreach ($valuearray as $value) {
$string1='<div><input id="' .$myid . $vcount .'" type="checkbox" size="1" value="'.$value.'" name="'.$myid.'[]">';
$string2 = '<label for ="'.$myid . $vcount . '">'.$value .'</label></div>';
$vcount++;
echo $string1.$string2;
}
$x++;
echo '<div style="clear:both"> </div>';
}while ($x<$arraycount);
/*Now show the submit button. */
echo '<div>';
echo $submitbutton; //show the submit button
echo '</div>';
?>


Get a VIP membership