Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mrfoggg opened this issue May 12, 2023 · 1 comment
Closed

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

mrfoggg opened this issue May 12, 2023 · 1 comment
Labels
question Further information is requested

Comments

@mrfoggg
Copy link

mrfoggg commented May 12, 2023

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.

@mrfoggg mrfoggg added the question Further information is requested label May 12, 2023
@mrfoggg
Copy link
Author

mrfoggg commented May 12, 2023

sory
$('#id_delivery_phone').djangoSelect2({ language: {noResults: () => '111'}, });

@mrfoggg mrfoggg closed this as completed May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant