That would be nice. I think there are more people who can use this. 2012/5/14 Richard Vézina <ml.richard.vez...@gmail.com>
> I merge autocomplete with SELECT_OR_ADD_OPTION and name it : > AutocompleteWidgetSelectOrAddOption > > It available here at the bottom of the thread : > https://groups.google.com/forum/?fromgroups#!topic/web2py/9KamKgHKUwU > > Or I will create a web2py slice soon, I hope... > > Richard > > > > On Mon, May 14, 2012 at 12:32 PM, Remco K <remc...@gmail.com> wrote: > >> Thank you very much, Anthony! This was exactly what i was looking for. >> Problem solved. >> >> Op vrijdag 11 mei 2012 19:07:32 UTC+2 schreef Anthony het volgende: >> >>> Are you trying to auto-complete a reference field, and you want to be >>> able to add new records to the referenced table? The built-in autocomplete >>> widget doesn't handle that out of the box, but upon submission, you could >>> check the request variables, and if the submitted value doesn't belong to >>> an existing record in the referenced table, you could do an insert: >>> >>> Model: >>> >>> db.define_table('category', Field(name)) >>> >>> db.define_table('article', >>> Field('title'), >>> Field('body', 'text'), >>> Field('category', db.category, >>> widget=SQLFORM.widgets.autocom**plete(request, db.category. >>> name, id_field=db.category.id))) >>> >>> Controller: >>> >>> def myfunction(): >>> if request.post_vars._**autocomplete_name_aux and not request. >>> post_vars.category: >>> request.post_vars.category = db.category.insert(name=reques**t. >>> post_vars._autocomplete_**name_aux) >>> return dict(form=SQLFORM(db.article).**process()) >>> >>> When you use the autocomplete widget on a reference field, it submits >>> the display value in a special field named _autocomplete_[display_field_ >>> **name]_aux, and the actual field value is the record ID of the >>> referenced record associated with the display value. However, if you enter >>> and submit a display value that does not have an associated record in the >>> referenced table, the reference field value will simply be empty (though >>> the _autocomplete_..._aux field will contain the submitted display value). >>> >>> For example, when submitting a new article, suppose you enter >>> "programming" in the category input field, but "programming" does not yet >>> exist in the db.category table. In that case, request.post_vars.category >>> will be empty, and request.post_vars._**autocomplete_name_aux will >>> contain the word "programming". In that case, the above code inserts >>> "programming" into the db.category table and stores the new record ID in >>> request.post_vars.category. When the form is then processed, the new >>> db.article record will be created, with the new db.category record ID >>> stored in the db.article.category field. >>> >>> Perhaps the autocomplete widget should handle this automatically (with >>> an optional setting). >>> >>> Anthony >>> >>> On Thursday, May 10, 2012 12:44:51 PM UTC-4, gfdgdgfdg wrote: >>>> >>>> Hello everyone, >>>> >>>> I'm looking for a way to get an auto-complete field combined with >>>> adding non-existing item to the DB. I've seen a website which >>>> uses this functionality (demo: >>>> http://www.tellmehow.nl/video.**html<http://www.tellmehow.nl/video.html>) >>>> >>>> I have already tried SELECT_OR_ADD_OPTION but i don't like drop-downs... >>>> >>>> Thanks in advance! >>>> Remco >>> >>> >> Op vrijdag 11 mei 2012 19:07:32 UTC+2 schreef Anthony het volgende: >> >>> Are you trying to auto-complete a reference field, and you want to be >>> able to add new records to the referenced table? The built-in autocomplete >>> widget doesn't handle that out of the box, but upon submission, you could >>> check the request variables, and if the submitted value doesn't belong to >>> an existing record in the referenced table, you could do an insert: >>> >>> Model: >>> >>> db.define_table('category', Field(name)) >>> >>> db.define_table('article', >>> Field('title'), >>> Field('body', 'text'), >>> Field('category', db.category, >>> widget=SQLFORM.widgets.autocom**plete(request, db.category. >>> name, id_field=db.category.id))) >>> >>> Controller: >>> >>> def myfunction(): >>> if request.post_vars._**autocomplete_name_aux and not request. >>> post_vars.category: >>> request.post_vars.category = db.category.insert(name=reques**t. >>> post_vars._autocomplete_**name_aux) >>> return dict(form=SQLFORM(db.article).**process()) >>> >>> When you use the autocomplete widget on a reference field, it submits >>> the display value in a special field named _autocomplete_[display_field_ >>> **name]_aux, and the actual field value is the record ID of the >>> referenced record associated with the display value. However, if you enter >>> and submit a display value that does not have an associated record in the >>> referenced table, the reference field value will simply be empty (though >>> the _autocomplete_..._aux field will contain the submitted display value). >>> >>> For example, when submitting a new article, suppose you enter >>> "programming" in the category input field, but "programming" does not yet >>> exist in the db.category table. In that case, request.post_vars.category >>> will be empty, and request.post_vars._**autocomplete_name_aux will >>> contain the word "programming". In that case, the above code inserts >>> "programming" into the db.category table and stores the new record ID in >>> request.post_vars.category. When the form is then processed, the new >>> db.article record will be created, with the new db.category record ID >>> stored in the db.article.category field. >>> >>> Perhaps the autocomplete widget should handle this automatically (with >>> an optional setting). >>> >>> Anthony >>> >>> On Thursday, May 10, 2012 12:44:51 PM UTC-4, gfdgdgfdg wrote: >>>> >>>> Hello everyone, >>>> >>>> I'm looking for a way to get an auto-complete field combined with >>>> adding non-existing item to the DB. I've seen a website which >>>> uses this functionality (demo: >>>> http://www.tellmehow.nl/video.**html<http://www.tellmehow.nl/video.html>) >>>> >>>> I have already tried SELECT_OR_ADD_OPTION but i don't like drop-downs... >>>> >>>> Thanks in advance! >>>> Remco >>> >>> > -- Met vriendelijke groet, Remco Klappe