Hi,

I just wanted to follow up on this for other people that may try to do
this same type of thing.   I'm not sure if this is the "best way"...
but it does seem to work.


class MyValidator(validators.Schema):
    def to_python(self, value, state=None):
        # deal with the issue that hidden field is NOT changed if 
        #   all text is deleted in the text input field
        if value['text'] == '':  
           value = value['text']
        else:
           value = value['hidden']
        # skip the to_python call in *Schema*, and go right to the 
        # FancyValidators call...  (better python way of doing this?)
        super(validators.Schema,self).to_python(value, state)
        return value

    # make sure Schema's _to_python isn't called either...
    #   it won't like the value change above. 
    _to_python = None

# then a small modification to my AutoCompleteField (add validator)

class MyAutoCompleteField(widgets.AutoCompleteField):
    validator = MyValidator(not_empty=True)

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

Hopefully, this will help somebody.

-Laurin

-----Original Message-----
From: Christoph Zwerschke <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: [TurboGears] Re: using hidden value in AutoCompleteField Widget
Date: Mon, 31 Mar 2008 09:57:07 +0200

Laurin schrieb:
> 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?

You should be able to do such tricks with a custom validator.

-- Christoph




!DSPAM:1,47f09a8b220203627260686!

-- 
Laurin Killian
Streamlined Development
http://www.streamlined-dev.com
(860) 445-0408



--~--~---------~--~----~------------~-------~--~----~
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