Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #777 (closed defect: worksforme)

Opened 13 years ago

Last modified 12 years ago

Impossible to programatically set an AutoCompleteField default value

Reported by: godoy Owned by: anonymous
Priority: high Milestone: 0.9a5
Component: TG Widgets Version: 0.9a4
Severity: critical Keywords:
Cc:

Description

Hi! With the following widget declaration I am not being able to set the value of its text_field programatically:

    endereco = widgets.AutoCompleteField(
        search_controller="/clientes/search_endereco",
        search_param="endereco",
        result_name="enderecos",
        text_field = widgets.TextField(name = 'endereco_text',
                                       attrs = {'size':51},
                                       label = _(u'Endereço'),
                                       validator = validators.UnicodeString(if_empty = None)),
        )

I've tried attributing values to it using the following idioms:

  • dict(endereco = value)
  • dict(endereco_text = value)
  • dict(text_field = value)
  • dict(text = value)
  • dict(widget = value)
  • {'endereco.widget': value}

and some more combinations based on the generated HTML and the source code. I can't precisely say when this started hapenning, but it was with some of the latest changes.

Here I have:

% tg-admin info | sort
cElementTree 1.0.5-20051216
Cheetah 1.0
CherryPy 2.2.0
elementtree 1.2.6
elementtree 1.2.6
FormEncode 0.5.1
FormEncode 0.5.1
kid 0.9
nose 0.8.4
Paste 0.5
PasteDeploy 0.5
PasteScript 0.5
PyProtocols 1.0a0
RuleDispatch 0.5a0
setuptools 0.6a11
simplejson 1.3
SQLObject 0.7.1dev-r1707
TurboGears 0.9a5dev-r1207
TurboJson 0.9.2dev-r1204
TurboKid 0.9.4dev-r1123

This makes this kind of field unusable for editing data.

Attachments

ticket777.zip Download (32.7 KB) - added by godoy 13 years ago.

Change History

comment:1 Changed 13 years ago by alberto

  • Component changed from CherryPy to Widgets

Have you tried:

dict(endereco=dict(endereco_text=value))

This is happening since [918] when AutoCompleteField became a CompoundWidget? to accomodate the hidden_field.

This should be emphazized in the docs... the difference between compound and simple widgets:

compound widget's values are always dicts simple widget's values can be whatever, but usually strings or ints. repeating widgets expect lists (maybe any iterable?)

comment:2 Changed 13 years ago by godoy

  • Component changed from Widgets to CherryPy

In my controller I have this:

            valores = dict(
                # ...
                endereco = dict(endereco_text = fornecedor.endereco),
                # ...
                )

        return dict(
            # ...
            data = valores,
            # ...
            )

and in my Kid template I have:

            <span py:replace="formulario.display(value = data, action='%s/update/' % root_link, method = 'post')" />

So if you're asking about the nested dicts I believe I did, unless you were asking about a third level -- mine "only" has two levels.

comment:3 Changed 13 years ago by godoy

It used to work before when we were discussing that bug in toolbox and the traceback that "disappeared" with FF 1.5.0.2. It is by that time -- maybe a little before that -- that it stopped working. So it definitely worked after this became a CompoundWidget?.

comment:4 Changed 13 years ago by alberto

You're last example should be working... This is certainly a bug.

comment:5 Changed 13 years ago by alberto

Sorry, too fast... Try:

value = dict(endereco=dict(text=value))

I think 'endereco_text' should be 'text'. I'm not sure when this was changed... Michele?

I've tried it in an interactive session and seems to work.

P.S: Isn't this more related to Widgets than CherryPy??

comment:6 Changed 13 years ago by godoy

  • Component changed from CherryPy to Widgets

Sorry... I haven't paid attention to the component. I believe I have already tried dict(text=value), but I'll do it again (see my description and you'll see that this is there). I named the text_field later to see if I could access it somehow, but it didn't work. I don't believe it was some change introduced by Michele with regards to this naming scheme :-)

So, this "value = " should be in my Kid template? Or at the dictionary where I declare the values for the several fields that are available in this form? I suppose it is the latter since the first wouldn't make sense for more than one field...

comment:7 Changed 13 years ago by alberto

{{ value = dict(endereco=dict(text="Something")) form.display(value=value) }}}

comment:8 Changed 13 years ago by godoy

Nope, it didn't work. I even added a third level dictionary at my controller...

I'll try reproducing it in a minimal application and I'll attach it here (if I don't find my mistake while doing that).

Changed 13 years ago by godoy

comment:9 Changed 13 years ago by godoy

This reproduces the problem with the command you gave. I'll be trying other variations based on this project and will tell here if something works.

comment:10 Changed 13 years ago by anonymous

  • Status changed from new to closed
  • Resolution set to worksforme

It's not a bug in AutoCompleteField but in you app. Try:

    @turbogears.expose(html = 'ticket777.templates.clients')
    def index(self):
        values = dict(
            endereco = dict(endereco_text = 'Default Value'),
        )

In the Clients controller. You had 'addresses' instead of 'endereco' and 'text' instead of 'endereco_text'. A snippet form the form so you can compare:

class widgets_clients_addresses(widgets.WidgetsList):
    endereco = widgets.AutoCompleteField(
        search_controller="/clients/search_address",
        search_param="address",
        result_name="addresses",
        text_field = widgets.TextField(name = 'endereco_text',
                                       attrs = {'size':51},
                                       label = _(u'Endereço'),
                                       validator = validators.UnicodeString(if_empty = None)),
        )

my_form_address = widgets.TableForm(fields = widgets_clients_addresses())

comment:11 Changed 13 years ago by godoy

Silly me. Indeed it works and I haven't fully searched and replaced the text from my application to this test case.

Sorry... So, it is some bug in my code that I need to find. Probably something as silly as this :-)

Thanks for your time.

comment:12 Changed 13 years ago by alberto

You're welcome :)

BTW: This has nothing to do to possible renames as I've mentioned. The name of the attribute inside AutoCompleteField that holds the TextField? ('text') has nothing to do with the actual name of the widget you pass as 'text_field', in this case 'endereco_text'. Sorry for the disinformation.

Alberto

Note: See TracTickets for help on using tickets.