Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development
Goto page 1, 2  Next

Problem with spaces and foreign characters

Author Message
Peter321



Joined: 25 Apr 2005
Posts: 9

Posted: Wed Apr 27, 2005 - 5:46 am    Post subject: Problem with spaces and foreign characters Reply with quote

Hi there,

I'm no programmer, but don't mind modifying html, so I took a shot at modifying Revs Yell.com widget:

http://www.dashboardwidgets.com/showcase/details.php?wid=138

to make it work with the Danish yellow pages.

I got it working, and will change the design to fit more with the danish pages design, but I have run into a problem.

When ever I enter a search term containing danish characters (. , , , , ) or a space (" ") I can't search - nothing happens when I press enter.

You can download it from the showcase here:

http://www.dashboardwidgets.com/showcase/details.php?wid=147

Any suggestion will be more than welcome Very Happy


cheers
Peter
View user's profile Send private message Send e-mail Widgets
damnman2k



Joined: 28 Apr 2005
Posts: 2
Location: Norway

Posted: Thu Apr 28, 2005 - 9:08 am    Post subject: Suggestion for whitespaces Reply with quote

Hi,
i made myself a modified version of the danish yellow pages widget and struck the same problem myself. Haven't figured out the ,, bit yet, but you can replace spaces in the search strings wit '+' to mak it work. It works with my homegrown norwegian phonebook lookup.

its something like:
Code:

searchfield.value.replace(/[\s]/gi, '+')


which will return the string in searchfield with alll the spaces replaced with '+' characters. Now to go headon with our strange nordic characthers...

cheers
Karl G
View user's profile Send private message Send e-mail Widgets
Peter321



Joined: 25 Apr 2005
Posts: 9

Posted: Thu Apr 28, 2005 - 3:43 pm    Post subject: Reply with quote

HI Karl

I wonder if one could do the same with the and replace them with "a", "o", and "aa" - at least the danish yellow pages seems to find things with and even if you use the subsitute characters?

Not the best solution though.

I hope some clever widget programmer can help us out - I've checked the Wikipedia widget and it searches OK with .

I think I'll try and PM the author.

cheers
Peter
View user's profile Send private message Send e-mail Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Thu Apr 28, 2005 - 7:36 pm    Post subject: Reply with quote

I'm really beginning to think that this is a bug with widget.openURL...

My idea was to replace the characters in question with their respective ASCII hex codes, prefixed with % for the browser, then send that to safari. This SHOULD work perfectly fine, but it doesn't. Here's the code I was using, in case anyone is wondering:

Code:
function performSearch() {
    var name = document.getElementById('searchInput').value.replace(/[\s]/gi, '+');
    var city = document.getElementById('cityInput').value.replace(/[\s]/gi, '+');
    var address = document.getElementById('addressInput').value.replace(/[\s]/gi, '+');
   
    name = encode(name);
    city = encode(city);
    address = encode(address);

    var url = "http://www.degulesider.dk/vbw/super/resultat.do?compTrade=" + name + "&compZip=&compCity=" + city + "&compAddress=" + address + "&compRegionID=&compPhone=";

    document.getElementById('searchInput').value = "";
    document.getElementById('cityInput').value = name;
    document.getElementById('addressInput').value = "";
   
    widget.openURL(url);
}

function encode(input) {
    hexOutput = "";
       
    for (i=0; i<input.length; i++) {
        hexOutput = hexOutput + '%' + Dec2Hex(input.charCodeAt(i));
    }
    return hexOutput;
}
function Dec2Hex(Decimal) {
    var hexChars = "0123456789ABCDEF";
    var a = Decimal % 16;
    var b = (Decimal - a)/16;
    hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
    return hex;
}


Of course, this works just fine when anything other than , etc. are typed into the search boxes. Even when I just set the url variable to:
Code:
var url = "http://www.degulesider.dk/vbw/super/resultat.do?compTrade=%68%E5%75%73&compZip=&compCity=&compAddress=&compRegionID=&compPhone=";

(%68%E5%75%73 is hus Smile )
then openURL that, without pulling anything from the search boxes, it still doesn't work. This is a perfectly legitimate url, if you copy and paste it into safari, it will pull up the yellow pages site with the results for hus.

No matter how the "foreign" characters are encoded, it seems that openURL converts them on the fly, and chokes when it hits one of these characters.

Unfortunately, my wikipedia widget also fails to open safari with an article with foreign characters. These characters only work when typed into the search box, then the page is pulled right into the widget. This uses XMLHttpRequest() rather than openURL(). When clicking the 'wikipedia.org' button that pulls the article into safari, it will also choke if any of these characters are used.

I'm stumped. The only workaround I can think of, is to use XMLHttpRequest to pull the search results into the widget, like I've done with wikipedia. This makes the project quite a bit more involved, but it will make a better widget at the same time...
View user's profile Send private message Send e-mail Visit poster's website Widgets
Peter321



Joined: 25 Apr 2005
Posts: 9

Posted: Fri Apr 29, 2005 - 12:37 am    Post subject: Reply with quote

HI Sean

Thanks for your input - too bad about the open.URL - will you report this to apple (are you a registered ADC member?) - it would be nice if they fixed it.

Making the whole thing in the widget is a bit too complicated for me Embarassed

Anyway, I actually prefer that it opens safari, as there are a number of extra posibilities for further search that might be too complicated for a widget,

cheers
Peter
View user's profile Send private message Send e-mail Widgets
icep



Joined: 29 Apr 2005
Posts: 7

Posted: Fri Apr 29, 2005 - 8:28 pm    Post subject: Reply with quote

have you tryed just to add this in <?xml version="1.0" encoding="utf-8"?> kind of warked for me... but i need my to change %F6 %E4 %E5... Just don't know how to Razz
View user's profile Send private message Send e-mail Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Fri Apr 29, 2005 - 8:57 pm    Post subject: Reply with quote

icep wrote:
have you tryed just to add this in <?xml version="1.0" encoding="utf-8"?> kind of warked for me... but i need my to change %F6 %E4 %E5... Just don't know how to Razz


icep, if you look above, i posted a code snippet that will convert the characters to %F6 %E4, etc. What do you mean by "kind of worked"? Does openURL work for you with the -type characters?
View user's profile Send private message Send e-mail Visit poster's website Widgets
icep



Joined: 29 Apr 2005
Posts: 7

Posted: Sat Apr 30, 2005 - 5:09 am    Post subject: Reply with quote

What i mean that kind of worked is that in the adressfield it shows and as we all know... You cannot have those characters in internet adress. so i only need the to convert nothing else like Malm will be Malm%F6 I found a some javascript online that converted those letter but it would not work...
View user's profile Send private message Send e-mail Widgets
bonAveo



Joined: 26 Apr 2005
Posts: 28
Location: Lillehammer, Norway

Posted: Mon May 02, 2005 - 4:21 pm    Post subject: Re: Suggestion for whitespaces Reply with quote

damnman2k wrote:
Code:

searchfield.value.replace(/[\s]/gi, '+')


which will return the string in searchfield with alll the spaces replaced with '+' characters. Now to go headon with our strange nordic characthers...


How do I use your code?
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Mon May 02, 2005 - 5:36 pm    Post subject: Reply with quote

Javascript's encodeURIComponent() function will return ascii hex codes (%E5, etc.) for any unicode characters. This is a bit cleaner than what I posted before. However, even if you send a fully hex encoded address string to openURL(), it still won't work if one or more of those hex codes stands for a unicode character... at least I haven't been able to get it to.
View user's profile Send private message Send e-mail Visit poster's website Widgets
damnman2k



Joined: 28 Apr 2005
Posts: 2
Location: Norway

Posted: Fri May 06, 2005 - 6:04 am    Post subject: Re: Suggestion for whitespaces Reply with quote

bonAveo wrote:
damnman2k wrote:
Code:

searchfield.value.replace(/[\s]/gi, '+')


which will return the string in searchfield with alll the spaces replaced with '+' characters. Now to go headon with our strange nordic characthers...


How do I use your code?


Hi, sorry for not replying sooner, I've had an accident involving my ibook/poweradapter and me walking past the table. I cant check it out just now, but i used 'replace' on the strings returned by the searchfield (if i remember correctly) class. I think something like this should work:


Code:

widget.openURL('someurl' + mySearchfield.value.replace(/[\s]/gi, ' '))


However, I wrapped it into my own function for easiser reading and experimentation.

Karl
View user's profile Send private message Send e-mail Widgets
Peter321



Joined: 25 Apr 2005
Posts: 9

Posted: Sat May 07, 2005 - 8:46 am    Post subject: Reply with quote

I found out that a workaround, at least for the danish yellow pages, is to replace the characters like this:

=ae
=oe
=aa

I assume this need to be done also for capital letters.

However, how do I add all these replacements to the searchstring, I can only get one to work - like: searchInput.value.replace('','ae')

How do I expand the replace function to handle more than one character?

Peter
View user's profile Send private message Send e-mail Widgets
Lars



Joined: 05 May 2005
Posts: 4
Location: Stockholm, Sweden

Posted: Sat May 07, 2005 - 10:16 am    Post subject: Reply with quote

Since you have already tried encodeURIComponent() I'm not sure this is going to help in this particular case, but otherwise I think escape() is kind of the standard method for taking care of this kind of situations.

escape() also takes care of spaces, so normally you would be able to replace all the above string conversion code with a call to escape().

Using some previous examples, escape('Malm to Hus') would return Malm%F6%20to%20H%E5us
View user's profile Send private message Send e-mail Widgets
Peter321



Joined: 25 Apr 2005
Posts: 9

Posted: Sat May 07, 2005 - 10:23 am    Post subject: Reply with quote

I fixed it by adding multiple .replace commands to each searchstring, replacing all the different characters as needed.

This is really just a quick hack, as each searchstring now has no less than 7 .replace commands attached, and it only solves the problem for the defined characters (so stuff like , , etc. still breaks the widget).

I guess this is as far as we can get until Apple fixes the bug.

cheers
Peter
View user's profile Send private message Send e-mail Widgets
kingmob



Joined: 07 May 2005
Posts: 68
Location: Vienna

Posted: Sat May 07, 2005 - 12:18 pm    Post subject: Same problem, still working on a solution. Reply with quote

I'm pretty sure it's a bug - I'm currently working on a widget for a local (austrian) routefinder app for public transport - it works like a charm, unless umlauts are used. we luckily only have four of them in german, but still..

tried both escape() and encodeURIComponent(), but to no avail. But there must be a working workaround - the Wikipedia widget has no problem accepting umlauts, at least the german ones. I'll take a look at it and report back what i find. If someone with better JavaScript skills than me (read: anyone) reads this, please take a look at the Wikipedia widget and try to find out what permits it to accept umlauts.
View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ NumberWidgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Goto page 1, 2  Next
Powered by phpBB © 2001, 2002 phpBB Group