Hi,

I like the functionality of an AutoCompleteField, but I want to use it
more effectively - and hopefully as nicely "packaged" as possible...

Basically, an AutoCompleteField is a compound widget with a TextField
where the user enters a value and a HiddenField that contains the
underlying "code value".   I think of this as similar to HTML's single
select field where each option has a value different from what is
displayed - but it is more interactive via AJAX.

My current code is like the Widget example code - it looks up states by
their two letter abbreviation.

Basically the value I want to be saved to the database is the 2 letter
state code - and I want the proper "display" value (full state name) to
show when it is retrieved from the database.

Here is my current solution - it works, but I'd like to put all
functionality into the MyAutoCompleteField Class.

# statemap is a dictionary like {'AK': 'Alaska', 'AL': 'Alabama', ...}

class MyAutoCompleteField(widgets.AutoCompleteField):
    def adjust_value(self, value=None, **params):
        """Adjust a value for displaying in a widget."""
        value = {'hidden': value, 'text': statemap[value]}
        return super(MyAutoCompleteField, self).adjust_value(value,
**params)

    # ideally, I'd like to similarly adjust the input value from the
form...

#...etc...
class MyController(controllers.Controller):
    @expose()
    def save(self, id=None, **kw):
        # I want only the "hidden" code for state_field...
        kw['state_field'] = kw['state_field']['hidden']
        # etc...   (save values to the database)


Is there some function I can override in MyAutoCompleteField Class to
catch the point where the input value is read - and only use the value
from the hidden field?   Or must I adjust things in the controller as
shown?

I hope to use a lot of these AutoCompleteFields for various lookups, and
I'd like to get it right, so it is easy to do each time.

Thanks for any suggestions,
-Laurin


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to