В Птн, 19/05/2006 в 19:45 +1000, Sam Stainsby пишет:
> Hi all,
> Just wondering what the current status of AJAX in Zope 3 is and how best
> to get started with it. I believe it would be useful to my work, but I'm
> not sure where to start. I know work is going on, but not sure what is
> going to be "officially" part of Zope 3 and what is just proof-of-concept.
> I'll probably go with whatever is likely to become part of official Zope 3
> or its extensions.
> My specific interests for the moment are AJAX-enabled widgets, such as a
> dropdown widget whose vocabulary changes based on the selection in a
> different dropdown within the same form. I don't want to pre-cache all
> possible vocabs, since there could be a quite a few large vocabs in my
> application. Perhaps there is a better way to do it, but I don't want to
> reload the entire page to update the widget. It is an
> accounting/inventory application that requires fast data entry.
> Any tips on how to get a Zope 3 sandbox into s state where I can do this
> sort of thing, and any specific tips for AJAXifying widgets?
> Cheers,
> Sam.
> _______________________________________________
> Zope3-dev mailing list
> Zope3-dev@zope.org
> Unsub: http://mail.zope.org/mailman/options/zope3-dev/garanin%40m-lan.ru
I use http://script.aculo.us/ AJAX-library. I attach my
'AutoCompleteWidget' for Zope3. 

#-*- coding:utf-8 -*-
from zope.interface import implements
from zope.app import zapi
from zope.app.form.browser import TextWidget, FloatWidget
from zope.app.form.interfaces import ConversionError
from zope.proxy import removeAllProxies

from z3fin.schema import convert_decimal

template = """%s
<div class="autocomplete" id="%s_autocomplete"></div>
<script type="text/javascript">new Ajax.Autocompleter('%s', '%s_autocomplete', '%s/auto_complete', {})</script>

class AutoCompleteWidget(TextWidget):
    cssClass = 'actextType'    
    def __call__(self):
        url = zapi.absoluteURL(self.context.context, self.request)
        html = super(AutoCompleteWidget,self).__call__()
        res = template % (html, self.name, self.name, self.name, url)
        return res

# Decimal widget 
class DecimalWidget(FloatWidget):        
    def _toFieldValue(self, input):
        if input == self._missing:
            return self.context.missing_value
                return convert_decimal(input)
                raise ConversionError(_("Invalid floating point data"), input)
    def _toFormValue(self, value):
        """Converts a field value to a string used as an HTML form value.

        This method is used in the default rendering of widgets that can
        represent their values in a single HTML form value. Widgets whose
        fields have more complex data structures should disregard this
        method and override the default rendering method (__call__).
        if value == self.context.missing_value:
            return self._missing
            res = removeAllProxies(value).to_eng_string()            
            return res.replace('.', ',')
Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to