Skip to content

Replace the message "No results found" the button #217

Closed
@mrfoggg

Description

@mrfoggg

Goal
If you simplify, I need Select2 with such parameters at the exit:

$("#id_contact_person").select2({ placeholder: "select person", allowClear: true, language: { noResults: function() { return " <button style="width: 100%" type="button" class="btn btn-primary" onClick=ajaxAddPersonr()'Save new person</button> </li>" } }, escapeMarkup: function (markup) { return markup; } })

Problem

`class ClientOrderAdminForm(forms.ModelForm):
def init(self, *args, **kwargs):
super().init(*args, **kwargs)
self.fields['person'].widget.can_view_related = False
self.fields['person'].widget.can_add_related = False
self.fields['incoming_phone'].widget.can_add_related = False
self.fields['incoming_phone'].widget.can_view_related = False

address = forms.ModelChoiceField(
    queryset=PersonAddress.objects.all(),
    label="Адрес доставки",
    required=False,
    widget=ModelSelect2Widget(
        model=PersonAddress,
        search_fields=('settlement__description_ua__icontains', 'settlement__description_ua__icontains'),
        dependent_fields={'person': 'person'},
        attrs={'data-placeholder': 'выберите адрес доставки контрагента', 'style': 'width: 80%;',
               'data-minimum-input-length': '0'}
    )
)

contact_person = forms.ModelChoiceField(
    queryset=ContactPersonShotStr.objects.all(),
    label="Контактное лицо",
    required=False,
    widget=ModelSelect2Widget(
        model=ContactPersonShotStr,
        search_fields=('full_name__icontains', 'phone__number__contains'),
        dependent_fields={'person': 'person'},
        attrs={
            'data-placeholder': 'выберите контактное лицо',
            'data-allow-clear': True,  # doesn't work
            'data-language': json.dumps({"noResults": format_html('<span>Some HTML</span>')}, indent=4),  # doesn't work
            'style': 'width: 80%;',
            'data-minimum-input-length': '0',
        }
    )
)`

Code Snippet
Please provide a code snippet of your problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions