Loading...
 
Features / Usability

Features / Usability


[SOLVED] CustomSearch, searching item between values

posts: 8357 Israel

I have trackers items with a text field used for size in meter (with decimal, IE: 8.45).

Do we have a search form element in the customSearch that will allow to filter (find) the items based on the size filter ?

  • Less than 10
  • 10 to 20
  • 20 to 30
  • 30 to 40
  • Above 40


I suppose I can use a mathematical field to create a value based on comparison but this would not be very elegant. ;-)

posts: 126729 United Kingdom

Hi B

I think you can use the daterange element to filter numbers, dates are numbers... not sure it does decimals though.

(it might need to be a nematic field too)

posts: 8357 Israel
Jonny Bradley wrote:

Hi B

I think you can use the daterange element to filter numbers, dates are numbers... not sure it does decimals though.

(it might need to be a nematic field too)


Well I have a look at it and experiment but I couldn’t find a way to a working solution (without decimal to start with).

May be I’m a missing something...
With 2 select fields (start and end)I got it right to find the number in between.

But how to make it work with a single select like my case ? (each option is a range between 2 values) ?


posts: 126729 United Kingdom
Bernard Sfez / Tiki Specialist wrote:
But how to make it work with a single select like my case ? (each option is a range between 2 values) ?

You would need some custom html (select) and JavaScript to fill the daterange inputs in - here's an example that makes a month dropdown search a datereange:

<div class="row"><div class="col-sm-3">
	{* add dropdown for months and year from May 1st*}
	<select id="daterange-presets" class="form-control">
		<option value=""></option>
		<option value="year">{tr}Financial Year To Date{/tr}</option>
		<option value="1">{tr}January{/tr}</option>
		<option value="2">{tr}February{/tr}</option>
		<option value="3">{tr}March{/tr}</option>
		<option value="4">{tr}April{/tr}</option>
		<option value="5">{tr}May{/tr}</option>
		<option value="6">{tr}June{/tr}</option>
		<option value="7">{tr}July{/tr}</option>
		<option value="8">{tr}August{/tr}</option>
		<option value="9">{tr}September{/tr}</option>
		<option value="10">{tr}October{/tr}</option>
		<option value="11">{tr}November{/tr}</option>
		<option value="12">{tr}December{/tr}</option>
	</select>
</div>
<div class="col-sm-5">
	{daterange _field="date" id="date" _to="now" _gap="30 days" class="form-control"}
</div></div>
$("#daterange-presets").change(function () {
		var val = $(this).val(),
			$from = $("#date_from_dptxt"),
			$to = $("#date_to_dptxt"),
			now = new Date(),
			year = now.getFullYear(),
			month = now.getMonth();

		if (val === "year") {
			if (month < 5) {
				year--;
			}
			$from.datepicker("setDate", "1/05/" + year).change();
			$to.datepicker("setDate", now).change();
		} else {
			val = parseInt(val);

			if (month < val) {
				year--;
			}

			$from.datepicker("setDate", "1/" + val + "/" + year).change();
			if (val === 12) {
				val = 0;
				year++;
			}
			$to.datepicker("setDate", "1/" + (val + 1) + "/" + year).change();
		}
		$("table#wpcs-0").find("th:first-child").trigger("sort");
		$('#customsearch_0').submit();
	});

Hmmm, sorry, that's more complicated than yours needs to be due to messing about with dates and years, but maybe it will help a bit?


posts: 8357 Israel

Awesome Jonny it gave ideas !

I will test a bit.
I wonder if it is not simpler to create a mathematical field and give a value based on range.
A kind of :

if tracker_field_value > 0 and < 10 = A
Else if > 10 and < 20 = B

Etc. Then I create a customSearch select with option="A,B,..." labels="less than 10, between 10 and 20, ..."

Cheaper and less complicate to maintain... 😉


posts: 8357 Israel

I wonder if it is not simpler to create a mathematical field and give a value based on range.
A kind of :

if tracker_field_value 0 and 10 and


After two hours playing with possible formulas and (damned) parentheses...

(if
(less-than permanameSize (add 80 0))
(str -80) (if (less-than permanameSize (add 120 0))
(str 80-120) (if (less-than permanameSize (add 160 0))
(str 120-160) (if (less-than permanameSize (add 200 0))
(str 160-200) (if (less-than permanameSize (add 240 0))
(str 200-240) (if (less-than permanameSize (add 280 0))
(str 240-280) (if (more-than permanameSize (add 280 0))
(str +280)))))))
)


Success ! 🏆