JavaScript-controlled link in Empty Text display

MikeEng's Avatar

MikeEng

23 Jun, 2010 11:00 PM

I'm trying to insert a link to open a new window without the toolbar and with a pre-set window size, using JavaScript.

I want to place this link into the field generated by emptyText.

Here's how I am generating it (around line 370)

if(matchCount <= 0){
                    results_ul.html('<li class="as-message">'+opts.emptyText+' <a class="suggest_new_trait" onClick="window.open(this.href,null,\'height=500,width=412,location=no,top=10,left=7,scrollbars=yes,toolbar=no\'); return false;" href="/member/profile/member-faq.php#suggest_new_trait">Suggest a new trait</a></li>');
                }

Viewing in Firebug, it looks fine, except that the case for "onClick" is transformed to "onclick". So the JavaScript doesn't work. Changing the case in Firebug will make it work.

I have the default variable at the top set to

matchCase: false,

Also, without any adjustments in Firebug, the JavaScript works if I comment out BOTH of these .toLowerCase() methods.

first one around line 305:

function processData(data, query){
                //if (!opts.matchCase){ query = query.toLowerCase(); }
                var matchCount = 0;

second one around line 337:

    if(str){
                        //if (!opts.matchCase){ str = str.toLowerCase(); }

Although that causes another problem because I don't want the search to be case sensitive.

But it doesn't work if I only comment out the first one or the second one.

It also doesn't work if I change the matchCase variable to true.

Any ideas?

  1. Support Staff 1 Posted by Drew Wilson on 23 Jun, 2010 11:15 PM

    Drew Wilson's Avatar

    Hey Mike,

    The code doesn't turn the emptyText variable into lower case.
    Not sure what's going on. I would have to see your working sample to debug it.

    I would suggest not altering the core code, because it isn't necessary.
    Why don't you just include the link inside the emptyText variable? Like:

    ... emptyText: 'No Results
    ...

    Thanks!
    Drew

    Hope that helps!

    Drew

  2. 2 Posted by MikeEng on 24 Jun, 2010 12:54 AM

    MikeEng's Avatar

    Thanks for the response, Drew.

    Good point - yes, that is what you created those variables for, but I forgot to mention,

    I actually tried putting the link inside the emptyText variable earlier and was having the same result. First though, I tried handling the click event with .live(), then .bind(). Both were giving me the same result as well. I thought hardcoding into the core code might help me track down the problem.

    I put my working code in a Pastebin.

  3. Support Staff 3 Posted by Drew Wilson on 24 Jun, 2010 01:02 AM

    Drew Wilson's Avatar

    You may not like this :) but you could try putting the javascript into the "href" attribute:

    <a href="javascript:function(){}"></a>
    

    strange that it is not working... have u tested it on various browsers?

    Drew

  4. 4 Posted by MikeEng on 24 Jun, 2010 01:54 AM

    MikeEng's Avatar

    Tried on Mac OS 10.6: Firefox 3.5.10 & Safari 4.0.4

    Full working example here. Pardon the Django cruft from taking it out of context, but it is basically behaving the same. There is a separate jQuery file (js/open_faq.js) which is running the window opening function on click for each of the "question mark" icons.

    Okay, I wouldn't LOVE that solution, but it actually wouldn't be terrible here.

  5. 5 Posted by MikeEng on 24 Jun, 2010 02:13 PM

    MikeEng's Avatar

    Drew, I tried what you suggested.

    First, in a simplified example with just the javaScript inside the href attribute, which is working.

    Then in context with the plugin, it doesn't work. I checked with a debugger, and the openFAQ function is in scope when it is called. I just copied and pasted the function and the href attribute which initiates the function into the plugin.

    Also, here's my updated version of the hacked plugin code in a Pastebin.

    Please help! I'm stumped.

  6. 6 Posted by Jo on 31 Jan, 2012 06:10 PM

    Jo's Avatar

    I tried the same with emptyText to have a link in there ... but no alert appearing in Firefox:

    emptyText: "No Results Found (

  7. 7 Posted by Jo on 31 Jan, 2012 07:14 PM

    Jo's Avatar

    I posted my quick 1st try solution here .... dont judge me:
    http://drew.tenderapp.com/discussions/autosuggest/279-how-can-i-cre...

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac