This topic is locked
[SOLVED]

 change "equals" to "between" for certain

7/4/2011 8:37:03 AM
PHPRunner General questions
jclabuschagne author

Goodday,
I wrongly posted this question in the tips & tricks section, sorry.
I need to change the default option of "equals" for certain fields to "between". Like a "Year" field, price field etc. This must not be implemented on all fields.
I need this specifically for the search panel.
I found a post to do this on the advanced search page (http://www.asprunner.com/forums/topic/13114-between-default-in-advanced-search/) but the code provided doesn't work in PHPRunner 5.3 build 7474.
I have implemented the code exactly as instructed, but I get the following script error:
Line: 119

Char: 1

Error: Unable to get value of the property 'asearchopt_Mileage': object is

null of undefined

Code: 0
This is the code I inserted just before </body>
<script>

function setSelectedIndex(s, v)

{

for ( var i = 0; i < s.options.length; i++ )

{

if ( s.options[i].text == v )

{

s.options[i].selected = true;

return;

}

}

}

setSelectedIndex(document.editform.asearchopt_Mileage,"Between"); ShowHideControls();

</SCRIPT>
Is there a possible workaround?

C
cgphp 7/4/2011

In the Javascript OnLoad page event of the list page:

var field = "your_field_name";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option").each(function() { this.selected = (this.text == filter); });
jclabuschagne author 7/5/2011

Hallo Cristian,
I have the following code in my javascript onload event of the list page:

pageObj.searchController.showSearchOptions();//to show the search panel by default
var field = "Mileage";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option").each(function() { this.selected = (this.text == filter); });


This doesn't seem to work. Any idea why?
I also have extra code to remove the "add field" and "show options" links from the search panel, and also to remove the "remove field" button from each field.
I removed this code to see if it has any effect, but it doesn't, the "Mileage" field stays on "contains".
Am I doing something wrong?
Thanks again for your help!

C
cgphp 7/5/2011



Hallo Cristian,
I have the following code in my javascript onload event of the list page:

pageObj.searchController.showSearchOptions();//to show the search panel by default
var field = "Mileage";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option").each(function() { this.selected = (this.text == filter); });


This doesn't seem to work. Any idea why?


It works for me.

Only the Mileage field is affected ?

Check the "Edit as" option of the Mileage field. Is it a Lookup wizard ?

jclabuschagne author 7/5/2011

Cristian,
The Mileage field was a lookup wizard field, but I changed it back to a normal textbox prior to posting in the forum.
I've tried the code also on another field, "Year", still not working. Keeps on showing "Contains". Could it be a problem if all the fields are varchar?
Then I tried it on a completely new "test" project, with a field with the name "Field1"
I put the following code in for testing purposes:

var field = "Field1";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option").each(function() { this.selected = (this.text == filter); });


When I tested it, it shows "Between" as default on the Options Dropdown of the search field, but just one textbox, and if I select something else like "Contains" and go back to "Between", then it is correctly displaying two textboxes. Something missing?
Thanks for your help

C
cgphp 7/5/2011



When I tested it, it shows "Between" as default on the Options Dropdown of the search field, but just one textbox, and if I select something else like "Contains" and go back to "Between", then it is correctly displaying two textboxes. Something missing?
Thanks for your help


Try this new code:



var field = "your_field_name";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option[value='"+filter+"']").attr("selected", "selected");


You have to update the field and filter vars for each field you want to add. You can use a for loop like this:



field = new Array("field_1","field_2","field_3");

filter = new Array("Between","Equals","More than");

for(var i = 0; i < field.length; i++)

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='"+filter[i]+"']").attr("selected", "selected");
jclabuschagne author 7/5/2011



Try this new code:



var field = "your_field_name";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option[value='"+filter+"']").attr("selected", "selected");


You need to update the field and filter vars for each field you want to add. You can use a for loop like this:



field = new Array("field_1","field_2","field_3");

filter = new Array("Between","Equals","More than");

for(var i = 0; i < field.length; i++)

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='"+filter[i]+"']").attr("selected", "selected");



Christian,
I got the Mileage, Year and Price fields showing "Between" as default with your code, thank you, but for some reason still there is just one textbox displayed for each of the fields.
Here is the code:

field = new Array("Mileage","Year","Price");

filter = new Array("Between","Between","Between");

for(var i = 0; i < field.length; i++)

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='"+filter[i]+"']").attr("selected", "selected");


I also tested this on the test project(with adapted code), same results.

C
cgphp 7/5/2011



but for some reason still there is just one textbox displayed for each of the fields.


???
Could you post a screenshot or a demo ?

jclabuschagne author 7/5/2011



???
Could you post a screenshot or a demo ?



IF it would help, the address is www.lowveldused.co.za/carsdb2/cars_public_list.php

C
cgphp 7/5/2011
field = new Array("Mileage","Year","Price");

filter = new Array("Between","Between","Between");

for(var i = 0; i < field.length; i++)

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='"+filter[i]+"']").attr("selected", "selected").parents().eq(0).trigger("change");
jclabuschagne author 7/5/2011


field = new Array("Mileage","Year","Price");

filter = new Array("Between","Between","Between");

for(var i = 0; i < field.length; i++)

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='"+filter[i]+"']").attr("selected", "selected").parents().eq(0).trigger("change");



Thanks Cristian, that worked perfectly, everything is fine now.
Sorry to be a bother, but how can I add custom text to the search panel? What I want to do is: Instead of having just two textboxes, have it in the format:
Mileage

and [textbox]
this is just to make it easier for the user to understand what to do.(also, I am hiding the options fields, so the user wouldn't understand why there is two textboxes) The textboxes can stay as is(it works perfectly, thanks), just the extra text is needed.
Must I edit the _search_panel.php manually?

Osteele 7/5/2011

Hello. I like what you have done with your site. May I make a suggestion. When choosing car make for example, it would be nice if the model field could auto-populate with available models. In a popup window I suppose. I had seen this done elsewhere, but for the life of me I cannot remember where. As a matter of fact, I may have had the code a while back, but cannot remember what pc I had it running on. Sorry
Good luck!

jclabuschagne author 7/6/2011



Hello. I like what you have done with your site. May I make a suggestion. When choosing car make for example, it would be nice if the model field could auto-populate with available models. In a popup window I suppose. I had seen this done elsewhere, but for the life of me I cannot remember where. As a matter of fact, I may have had the code a while back, but cannot remember what pc I had it running on. Sorry
Good luck!


Goodday Osteele,
Glad you like my site, the functionality for populating the model field according to the Make field have just been done. I just made both the Make field and the Model field lookup wizards, and on the model field I set the "This field is dependant on" part to make.
That's that.
Now I just need to figure out how to add custom text to the search panel.
Cheers
Johan

C
cgphp 7/6/2011



Thanks Cristian, that worked perfectly, everything is fine now.
Sorry to be a bother, but how can I add custom text to the search panel? What I want to do is: Instead of having just two textboxes, have it in the format:
Mileage

and [textbox]
this is just to make it easier for the user to understand what to do.(also, I am hiding the options fields, so the user wouldn't understand why there is two textboxes) The textboxes can stay as is(it works perfectly, thanks), just the extra text is needed.
Must I edit the _search_panel.php manually?


With jquery you can hide the dropdown and append a custom text before and after the first textbox.

jclabuschagne author 7/11/2011



With jquery you can hide the dropdown and append a custom text before and after the first textbox.


Cristian,
I do not know the jquery language very well, could you please point me to the correct selector so I can use the prepend and append functions?
I tried

$("input[id*='value'][id*='" + field[i] +"'] ).prepend("Between ");//a modified version of your code above


and

$(".value_Year_12" ).prepend("Between "); // the id of the input is value_Year_12


The problem is I do not know what to select and modify with prepend and append.
Will prepend and append even work?

C
cgphp 7/11/2011

We can remove the filter array:

field = new Array("Mileage","Year","Price");

for(var i = 0; i < field.length; i++)

{

$("select[id*='srchOpt'][id*='" + field[i] +"'] option[value='Between").attr("selected", "selected").parents().eq(0).trigger("change").hide();

$("input[id^='value_"+field[i]+"'][type='text']").before("Between<br/>").after("<br/>and<br/>");

}
jclabuschagne author 7/12/2011

Thanks Cristian, it looks great now.
Thanks alot for all your help!

C
choanhemnhe 8/3/2011



In the Javascript OnLoad page event of the list page:

var field = "your_field_name";

var filter = "Between";

$("select[id*='srchOpt'][id*='" + field +"'] option").each(function() { this.selected = (this.text == filter); });



Thanks Cristian,

this works for me <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59926&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

A
aramuni 8/6/2011

Very nice and usefull Cristian. Thank you.
I´ve tried to repeat the value of the first field in the second field but without success.
Sometimes times the user needs to filter one day only.
This is possible?

C
cgphp 8/7/2011

Please, post your code.