Hello ajaxers,

I wrote a simple jQuery plugin for form validations.
It makes a query server side and uses a placeholder to show the results.
After that the user can click in a link choosing the value, assigning
it to a input element and erasing the placeholder.

For example I have a input hidden with the city code, another input
text with the city name. When the use click a button, the plugin look
at the text in the city name input (by callback) and make a query in
the server showing the list of cities. Then the user choose one by
clicking in a link. The plugin erases the placeholder and put (by
callback) the city code and city name (which are in the href of the
link) into the inputs.

The problem is this works in FF, Opera, but have a bug in IE !!!

The code with problem is:

            // assign a event for replacing the click of the links of
the results
            $(settings.choiceclass, pl).each(function(){
                j(this).bind("click", self.revertPlaceholder);
                //alert(j(this).html());
            });
If the comments in the alert line are removed, I see the name of any city.
However is funny having also a similar code which works in IE!!!

            $(settings.paginationclass, pl).each(function(){
                j(this).bind("click", self.replacePlaceholder);
            });
This is for the pagination links when I have more elements.

Somebody has any idea whats happening?

The full code is:

// start of code

$.fn.lookupAction = function(options) {
        // Options
        var settings  = {
                "url": null,
        "method" : "POST",
                "placeholder": null,
                "onget": null,
                "onset": null,
                "choiceclass": ".choicelink",
                "paginationclass": ".paginationlink > a",
        "event" : "click"
        };
        var j = jQuery;
    if(options)
        j.extend(settings, options);
        // Set up

    j(this)[settings.event](function() {;
        // save this to self because this changes when scope changes
        var self = this;

        // prevent throwing an exeption if edit field is clicked again
        if (self.editing) return;
        self.editing    = true;
        
        self.replacePlaceholder = function()
        {
            try {
                urlsearch = j(this).attr("href");
                j(settings.placeholder).html(self.revert);
                jQuery.ajax({
                   type : "GET",
                   url  : urlsearch,
                   success: self.overridePlaceholder
                   });
            } finally {
                self.editing    = false;
            }
            return false;
        }

        self.revertPlaceholder = function()
        {
            self.editing    = true;
            try {
                myJSONtext = j(this).attr("href");
                var myObject = eval('(' + myJSONtext + ')');
                if (settings.onset)
                    parameters = settings.onset(myObject);
                j(settings.placeholder).hide();
                j(settings.placeholder).html(self.revert);
            } finally {
                self.editing    = false;
            }
            return false;
        }

        self.overridePlaceholder = function(content)
        {
            pl = j(settings.placeholder).html(content);
            // assign a event for replacing the click of the links in
the pagination
            $(settings.paginationclass, pl).each(function(){
                j(this).bind("click", self.replacePlaceholder);
            });
            // assign a event for replacing the click of the links of
the results
            $(settings.choiceclass, pl).each(function(){
                j(this).bind("click", self.revertPlaceholder);
                //alert(j(this).html());
            });
        }

        // start the query
        try {
            j(settings.placeholder).show();
            try {
                self.revert     = j(settings.placeholder).html();
                parameters = null;
                if (settings.onget)
                    parameters = settings.onget();
                jQuery.ajax({
                       type : settings.method,
                       url  : settings.url,
                       data : parameters,
                       success: self.overridePlaceholder
                       });
            } catch(e) {
                j(settings.placeholder).html(e.message);
            }
        } finally {
            self.editing = false;
        }
    });

        // Don't break the chain
        return this;
}; // */

// end of code

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to