Hi David,

Thanks so much for your reply. Im checking the  videos at the google search.

So hopefully I'l develop a combobox with that.

Thanks so much sir!


El jue., 29 oct. 2020 a las 1:24, David Nugent (<[email protected]>)
escribió:

> This is known as a "combo box", somewhat different to a select.
>
> Check this google search: html5 combo box django
> <https://www.google.com/search?client=safari&rls=en&sxsrf=ALeKk027-UFoeoX339-nh4hcSV3LCXSS7A%3A1603944032147&ei=YD6aX9nLCNn99QO_rKLQAg&q=html5+combo+box+django&oq=html5+combo+box+django&gs_lcp=CgZwc3ktYWIQAzIICCEQFhAdEB4yCAghEBYQHRAeMggIIRAWEB0QHjoHCAAQRxCwAzoHCAAQyQMQDToECAAQDToGCAAQDRAeOgkIABDJAxANEB46CAgAEAgQDRAeOgoIABAIEA0QChAeUM4RWKsYYKMbaAFwAHgAgAH3AYgBoAySAQMyLTeYAQCgAQGqAQdnd3Mtd2l6yAEIwAEB&sclient=psy-ab&ved=0ahUKEwjZ-5mS9djsAhXZfn0KHT-WCCoQ4dUDCAw&uact=5>
>
> Some useful video tutorials + some explanations on how it all works.
>
> A simpler approach - override the widget class similar to how you have
> done, but there is no need to override them all and I would avoid doing so.
> If you just need to add some attributes, you can add to the attrs dict of
> the existing widget instead of replacing it entirely. Plenty of examples
> exist for that, including the (excellent) django documentation. For your
> combo box selector you would need to override the widget in order to render
> the html so you use something different to Select.
>
> Something like (except from a recent project of mine) the following in the
> form:
>
> class SomeForm(forms.Form)
> ...
>     HEAR_ABOUT_US = (
>         'Celebrant',
>         'brochure about us',
>         'funeral director',
>         'facebook page or post',
>         'medical or social worker',
>         'priest, pastor or minister',
>         'friend or family member',
>         'other...',
>     )
>  ...
>     hear_about = forms.CharField(label='Where did you hear about us?',
> max_length=64, required=False,
>                         widget=ListTextWidget(name='hear_about',
> data_list=HEAR_ABOUT_US),
>                         help_text='Please let us know how you heard about
> us (press down or click arrow for options)')
> ...
>
>
> And the widget, which could probably do with some improvement:
>
> class ListTextWidget(forms.TextInput):
>
>     def __init__(self, name, data_list, *args, **kwargs):
>         super().__init__(*args, **kwargs)
>         self._name = name
>         self._list = data_list
>         self.attrs.update(list=f'list__{self._name}')
>
>     def render(self, name, value, attrs=None, renderer=None):
>         text_html = super(ListTextWidget, self).render(name, value,
> attrs=attrs)
>         data_list = f'<datalist id="list__{self._name}">'
>         for item in self._list:
>             data_list += f'<option value="{item}">'
>         data_list += '</datalist>'
>         return (text_html + data_list)
>
>
> HTH, David
>
> On 29 Oct 2020, at 00:23, Walter Randazzo <[email protected]> wrote:
>
> Hi guys, How r u doing?
>
> I have a field called articulos that is foreign key,  in a form is defined
> as follow:
>
> *forms.py*
> from django import forms
> #from django.contrib.auth.models import User
> from .models import Stockmov
>
> class StockmovForm(forms.ModelForm):
>     class Meta:
>         model = Stockmov
>         #fields ="__all__"
>         fields =  ['articulo', 'motivo', 'Cantidad' ]
>         widgets = {
>
>         'articulo': forms.Select(attrs={'class':'form-control', 
> 'placeholder':'Articulo'}),
>
>         'motivo': forms.TextInput(attrs={'class':'form-control', 
> 'placeholder':'Motivo'}),
>
>         'Cantidad': forms.NumberInput(attrs={'class':'form-control', 
> 'placeholder':'Cantidad'}),
>         }
>         labels = {
>             'articulo':'', 'motivo':'', 'Cantidad':'',
>         }
>
> I want to allow the user to search an instance in the same  combobox
> articulo in the createview. Check the pic.
>
> Whats is the best native way to do that?Other alternatives?
>
> Thanks in Advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/692f2017-ab9e-40b7-8a7c-5c22bffaf368n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/692f2017-ab9e-40b7-8a7c-5c22bffaf368n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> <WhatIWant.png>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL7Dry60-w%2BQXZeQEPwjN6HKpk_Kw%2Bdv-yqCYfnCGrL4fshNTg%40mail.gmail.com.

Reply via email to