Forums Forums Search & Filter Pro Number Ranges Min-Max values

Tagged: 

Viewing 10 posts - 1 through 10 (of 15 total)
  • Anonymous
    #257902

    Hello, I am opening a separate thread because I think this requires special attention.

    In all number ranges, either single or from/to fields the following options should be available:

    – Custom sets of values… eg define your own min/max values that are step independent. Imagine the following scenario:

    Min/Max
    0-500
    500-1000
    1000-5000
    5000-50000
    50000-100000
    etc

    – On top of this feature, it would be a good idea to be able to have a checkbox of some sort that does not restrict you to either a min or a max value. Based on the example I set previously.

    Min/Max

    50000-100000
    100000+ (No max)

    NS

    Trevor
    #257981
    Anonymous
    #258012

    Awesome! And awesome support! Thanks Trevor!

    Trevor
    #258020

    Hi Nick. Do let me know if you get it working, and maybe you might be able to share your code?

    Anonymous
    #258031

    Yes, I will try to have a look at it tomorrow and report back. Busy days…

    Anonymous
    #258119

    So, here is my code, don’t know how you want to make use for it, but here it is in case it helps someone!

    First of all, I just set a couple of values in the admin, 0-100 – it makes no difference since I am unsetting the initial options anyway:

    function change_car_engine_size($input_object, $sfid) {
    		if($input_object['name']=='_sfm_car_engine_size') {
    			unset($input_object['options']);
    			$input_object['options']=array();
    			$arr = ['0','100','200','300','400', '500', '600', '700', '800', '900', '1000','2500','3000','3500','4000'];
    			foreach ($arr as $value) {
    				$new_option = new StdClass();
    				$new_option->value = $value;
    				$new_option->label = number_format($value, 0, ',', '.');
    				array_push($input_object['options'], $new_option);
    			}
    
    		}
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'change_car_engine_size', 10, 2);
    Anonymous
    #258123

    …New question… I have no idea how to initially pre-select the last biggest value for tha max input option?

    Trevor
    #258132

    Pre-select is not currently available, I am sorry. Thanks for sharing the code.

    Anonymous
    #258136

    Actually you can – sorry to prove you wrong!- just found it by examining the $input_object;

    I defined in the function:

    $input_object['default_max']=4000;
    $input_object['default_max_formatted']=4000;
    Trevor
    #258138

    Ah, but does it actually filter the results to that range?

Viewing 10 posts - 1 through 10 (of 15 total)