Just to follow up. I had to alter the autocompletefield.js to add a
hook to call an onchange function because i forgot that hidden fields
cannot have onchange functions...as far as I can tell. Not a
beautiful solution but it works. Thanks.
-Ian
On 10/9/06, Ian Wilson <[EMAIL PROTECTED]> wrote:
> Thank you.
> Yeah I haven't tried it but yeah that should do the trick. I didn't
> even think about putting in my own textfield and hiddenfield but that
> makes it even more flexible. I'll give it a try tonight. And I have
> to be honest I am excited I have wanted to use AutoComplete for a
> while.
> -Ian
>
> On 10/9/06, Kevin Horn <[EMAIL PROTECTED]> wrote:
> > When you set up the AC widget, you can pass in your own TextField and
> > HiddenField widgets, something like this (going from memory, this is not
> > actual working code):
> >
> > tf = TextField("textfieldname" ... attributes can be set here ... )
> > hf = HiddenField("hiddenfieldname" ... attrs can be set here ... )
> >
> > class FormWdigets(WidgetsList):
> > ac = AutoCompleteField(name="acname", text_field=tf,
> > hidden_field=hf)
> >
> > form = TableForm(fields=FormWidgets)
> >
> > That may not be it exactly, but should give you the idea...haven't tried it
> > with adding JS event handlers though.
> >
> > If you can't get the event handler working this way, there's always the
> > MochiKit Signal API, though. That might be worth a try.
> >
> > Hope this helps!
> >
> > Kevin H
> >
> >
> > On 10/9/06, Ian Wilson <[EMAIL PROTECTED]> wrote:
> > >
> > > Hello,
> > > I am going to jump on this thread since I have some AutoComplete
> > > questions and will probably have more. Its too bad i didn't see this
> > > before it was a struggle to get the hidden field to work. Has anyone
> > > been able to set the attributes of the textfield and hiddenfield? If
> > > I want to do some ajax when the user does select something from the
> > > autocomplete what is the best method without breaking the widget? I
> > > was thinking of adding an onChange method to the hidden field so that
> > > when a name is selected from the my list and it stores the id then the
> > > onchange js function will be called and I can go to the server and get
> > > the information for that name using Javascript.
> > >
> > > Right now I use this which does nothing(no errors, just nothing):
> > >
> > > attrs = {}
> > > attrs['text'] = dict(size=150)
> > > attrs['hidden'] = dict(onchange="selectPlant()")
> > > form = TableForm(
> > > fields=[
> > > AutoCompleteField(name='plantName',
> > > search_controller='getPlants', search_param='rawSearchWords',
> > > result_name='results', label="Plant:",
> > > attrs=attrs),...
> > >
> > > Maybe my dictionary is setup wrong I can't really see why this doesn't
> > work.
> > >
> > > Thanks,
> > > -Ian
> > >
> > > On 10/5/06, percious <[EMAIL PROTECTED] > wrote:
> > > >
> > > > found the answer. The AutoCompleteField automatically comes with a
> > > > "hidden" value. When you return your search results, return a tuple
> > > > like: (view, hidden):
> > > > @expose(format="json")
> > > > def search(self, searchString):
> > > > vars = self._generateVariables(self.iceProjectID)
> > > > varList = []
> > > > searchString = searchString.lower()
> > > > items = []
> > > > for var in vars.values():
> > > > if searchString in (var.tag+var.description).lower():
> > > > items.append(("%s - %s"%(var.tag,var.description),
> > > > var.id))
> > > > return dict(items=items)
> > > >
> > > > Then you can get your results something like the following:
> > > > @expose()
> > > > def addParameter(self, areaID, parameters=None):
> > > > if parameters!=None:
> > > > parameter = parameters['hidden']
> > > > variable = Parameter.get(int(parameter))
> > > > return dict(parameter=variable)
> > > >
> > > >
> > > > >
> > > >
> > >
> > >
> > > > > >
> > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---