last day (14 days later) » 

1:02 PM
0
A: Filter and search using Textbox

BillybobbonnetYou are almost right. Your keyUp event is ok but you could also avoid to use jQuery like this: "keyup .textInput": function(e, t) { var searchString = e.currentTarget.value; switch (e.which) { case 27: e.currentTarget.value = ""; searchTitle.set(""); break...

 
For this didn't quite get the hang of this line match = match || (value && value.match(regEx)); i am not searching for Categories,Cities. i want to perform search just on a field called title.
 
Then you need to replace the content of the searchFields array with an array of all the title fields content. Concerning the line you don't understand, match will not be false anymore if the regex match an item or one part of it. You might be confused to see duplicate values, this is called guarding: thoughtworker.in/2008/04/25/guarding-in-javascript
 
i don't understand why its throwing an error value.match is not a function.
 
no error on var regEx = new RegExp(currentSearchTitle , "i");? This is where you define the regex you use where you get the error, make sure the names match
 
nope. that's why i am confused. names are perfectly fine. i logged the regEx value too and its taking the values correctly from the textbox.
this is the error i am getting Exception in template helper: TypeError: value.match is not a function it might help in understanding what i am doing wrong.
 
1:02 PM
log currentSearchTitle too. currentSearchTitle is an array of strings, right?
 
currentSearchTitle is also giving the value as correct as whatever i am typing in the textbox
 
I meant searchFields sorry. It should be an array of string containing all your items's titles.
 
its returning all objects containing titles alongwith the id. here's what i am doing var searchField = Jobs.find({},{fields: {title:1}}).fetch();
 
try var tempSearchField = Jobs.find({},{fields: {title:1}}).fetch(); and then var searchField =_.pluck(tempSearchField , 'title');. This will extract all titles as an array of strings.
 
ok that works its returning array strings of titles only. but not performing the filtering. P.S: that error of value.match is not occuring now
 
1:02 PM
Do you get your items displayed?
 
Yes and I am getting the titles in console also. But it's not filtering the titles as I type in the text box
can you please look into this issue. why it is not returning filtered values.
 
Did you check if the keyup event is correctly triggered?
 
yes i did console.log to checck the values and its working. and its even returning the array of strings of all titles. but just not filtering it
 
I updated the code, it could have been wrong (again, not tested). Try with the new filter function, and make sure that item.title is your item title string.
 
filtering is still not working. :(
 
1:02 PM
You still return filtered; at the end of your function, right? Don't just say it does not work, instead try to get some info on what's going on like : console.log(item); in the each loop get you a collection document or not, console.log(filtered); gives you a cursor or not, if it does, is console.table(filtered.fetch()); giving you the correct results.
 
yes everytime you give a solution. i try to understand the code at each step by doing console.log() to know what that function or variable is returning. and when it doesn't work, i even try to do it using other functions in underscrorejs or using meteor document at my side.But when i fail completely i get back to you saying its not working. so when you suggest something different i compare it with my solutions to see what was i doing wrong.
 
so how is it going, regarding the questions above?
 
yes console.log(filtered) is giving a cursor containing the correct value by filtering.
 
Then I must check: you still return filtered; at the end of your function, right?
 
yes. iam returning filtered at the end of function
 
1:02 PM
I am puzzled. Just to sum it up: filtered is a cursor containing the correct values and you return it at the end of your function filterAndLimitResults. You call filterAndLimitResults in the helper that you use to display your results, so in HTML you have something like {{# each results}} where results is an helper like this: "results": function() {return filterAndLimitResults(Jobs.find());},. So the search is going fine but results aren't displayed. Is it still working when you use the dropdown only?
 
yes. i am doing exactly the same thing. just another thing i noticed there that the filtered is returning a cursor only in the each loop. not at the end of the function. i did console.log(filtered) in the each loop and at the function end. but the only place it is returning cursor is just inside the loop
 
You talk about the _.filter loop? See my edit from yesterday in my answer, I removed the _.each. Can you pls copy paste your js code in a fiddle? I can't get a clear idea.
 
Yes. i edited that as you updated the code. here's the fiddle with both the function and keyup event
 
Ok, you was replacing filtered by raw in the currentChosenCategory filter (the one after the currentSearchTitle filter). That's something you must do only with your first filter (or it will replace the previous filtered content. Try with this: jsfiddle.net/c0qL3kps
 
i removed that if condition in the currentChosenCategory filter. the text search works but the first time the app loads in the console.log()it returns the cursor but doesn't show any record in the UI and also the dropdownlist filters are not behaving properly.
 
1:02 PM
if it is only when your server reboot, it is just because the publication is missing I guess (not sure). If you reload the page after server reboot, it works properly?
 
no. it is not showing any records on reloads also. if it was from publication then how come it can filter the records?.it is returning cursor on console.log(). there's something in the function itself i guess.
 
What is console.log(filtered) returning just before return filtered;?
 
an empty array []. but why? because the console.log(filtered) at the currentSearchTitle condition is returning a cursor. where we are assigning filtered=raw. then why at the end of function this filtered is not having any values?
 
can you update the fiddle pls?
something must be happening inbetween
 
ok sure
here's the link for the fiddle jsfiddle.net/trv55Lhe
 
1:08 PM
ok I found an error, you kept a reference to raw where it should have been filtered
in currentChosenCategory
it should be
if (!currentChosenCategory || currentChosenCategory == "" || currentChosenCategory === "All categories")
{
filtered = _.filter(filtered, function (item) {
if(currentChosenCategory){
return item.ccategory === currentChosenCategory ;
}
});
}
try it
 
its the same. doesn't work.
 
try it with these logs jsfiddle.net/j6yfp7Ls
we'll see where it is going wrong
 
ok before currentChosenCategory its returning the cursor but after that its returning empty array's till last step
 
you forgot the if (!(!currentChosenCategory
missing a !
 
1:25 PM
ahh that's so stupid of me. it is working perfectly fine now.
Thanks alot for your help
 
wow glad it comes to an end
try to think in terms of patterns
as you can see, every filtering has the same structure
so if something is going wrong, start to look for differences between your patterns
 
ok
 
can you close the question please?
hardest 15 points I ever won :-)
 
yes i was about to mark it as best answer :)
i am so glad that finally it is done
Thanks alot for your help from the start
 
keep it up, that kind of mistake should become easier to solve when you will get some experience
your welcome :-)
good luck for your project
 
1:30 PM
Do you have a blog or something where i can follow you?
 
nope
I am a beginner as well
in javascript
 
me too. can you suggest something for a good read?
 
you can follow my likes in github.com/Billybobbonnet
I never learn from reading books, rather blogs
 
iam perusing the meteor docs everyday
 
good blog
from the david weldon from SO
 
1:32 PM
javascriptissexy.com i follow this for javascript tips
 
discovermeteor.com is often refered to
I don't know the book
but articles are fine
you need to look for meteor specific references too
 
yes i have the book. it mostly cover just the basics
blogs are good rather than books i guess.
 
well, I'll leave the chat. Feel free to poke me on boitalettre9@hotmail.com if needed
but I might have a lot of work in the next weeks
cant promise to be reactive
cya, and good luck with your project :)
 
Ok thanks. Thanks alot for your help. no problem
bye
 

last day (14 days later) »