At this time, it is possible to add CSS identifiers (IDs and Classes) only to the term elements, and not the containing form elements. It is a feature we plan to add to the next major update (V3), which we are currently working on.
To modify the input objects you would have to write your own code using the sf_input_object_pre filter.
Most objects in the form do have their own CSS class that you can target with Custom CSS. You can use the browser inspector to find these.
As to the first part of the question above, try changing the type of form field to Checkbox or radio and see if that looks closer in terms of the HTML structure. For me it does.
As to the second part, I understand. In your UL example, if that field had a filter selected, it would be the li that has the extra class to show it is selected, but CSS allows you to target the parent of an element that has a given class (in this case it would be the class sf-option-active). You can hide the checkbox with custom CSS as well.
Our sf_input_object_pre filter allows you to target these inner elements also.
AnonymousInactive
I tried using CSS, unfortunately Macs/ Safari refuse to honor display:none;
Regarding the code
// add indent to dropdown
function filter_function_name($input_object, $sfid87) //I cant change it to just 87 as its expecting a variable
{
if($input_object[‘name’]==’_my_field_name’) // this should be the class name?
{
//udpate this field before rendering
$input_object = ” “. $input_object;
}
return $input_object;
}
add_filter(‘sf_input_object_pre’, ‘filter_function_name’, 10, 2); // what is 10,2 is that something that I should be changing?
Sorry to be such a bother.
You can add classes for form elements using our Filter Input Object sf_input_object_pre filter.
AnonymousInactive
Thank you.
My php isn’t that great, would it would be something like;
function filter_function_name($input_object, $sfid=87)
{
if($input_object[‘name’]==’sf-level-1′)
{
//udpate this field before rendering
$input_object[‘attributes’][‘style’] = ‘margin-left:50px;’;
}
return $input_object;
}
add_filter(‘sf_input_object_pre’, ‘filter_function_name’, 10, 2);
AnonymousInactive
All of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/
Tweaks to code as per previous threads here:
// Search Filter
function filter_input_object($input_object, $sfid) {
if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) {
$new_options = array(); //the options added to this will replace all existing optoins in the field
foreach($input_object['options'] as $option) {
if ($option->value !== "")
{
//check to see if the option has a parent
$parent_id = wp_get_post_parent_id($option->value);
if(!$parent_id)
{
//then this option does not have a parent, so it must be a parent itself, add it to the new array
$option->label = get_the_title($option->value);
array_push($new_options, $option);
}
}
}
//now we have an array with only parent options in, so simply replace the one in the input object
$input_object['options'] = $new_options;
}
return $input_object;
}
add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Any ideas?
Are you saying that, on the S&F Pro form settings page, on the Posts tab, you tried it with the Primary sort as date and secondary sort as name? I would have thought that should have worked. as you say, there should be no need for the secondary sort, as the date would be sufficient.
My initial though would be that you could code around this using one of our filters. See here in the documentation.
If you use the filter sf_input_object_pre you get access to the options as an array, so you can order this array however you want, so you can use this to sort the array with php. But you would need to code this.
See here in the documentation.
If you use the filter sf_input_object_pre you get access to the options as an array, so you can order this array however you want.
You Do have access to the count variable, so you can use this to sort the array with php. But you would need to code this.
AnonymousInactive
Hey Trevor,
Thank you.
After numerous other options I tried the below but not sure I’m in the right zone (the custom class is added to the field so it’s partly working).
I just want to pull one of the options from that dropdown as the default on that page (selected option on page load).
Any pointers?
Thank you!
<?php function filter_input_object($input_object, $sfid) {
if ($input_object[‘name’] == ‘_sft_testcat’) {
$input_object[‘defaults’] = array(“Test”);
$input_object[‘attributes’][‘class’] = ‘mynew_class’;
}
return $input_object;
}
add_filter(‘sf_input_object_pre’, ‘filter_input_object’, 10, 2); ?>
Hey Ash
The best way to get the current value is to use our active query class:
https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
Because you want the actual value it might be best to use the array method and pull your value from there.
Alternatively, when using the sf_input_object_pre filter, the defaults should already be set to the current value from the URL, as its this default argument that is set by S&F and will be used to set the selected state.
Doing a var_dump of $input_object['defaults'] should show the currently active value, if you access it at the top of your function before you’ve made any modifications (note: this will always be an array even for single selection type fields)
Hope that makes sense?