-
Hello! I have an exactly the same question like the person here - https://stackoverflow.com/questions/78023093/put-link-anchor-in-select2-no-results-dropdown-message In this case a vessel with a code of "000000" does not exist, so it writes "No results found", but I want to have a link instead of this text that links the user to vessel creation page. I have found that if I copy noResults: function () {
return 'No results found';
}, to this for example: noResults: function () {
return 'No results found TEST';
}, It renders like so: Looks good. I then try to add a button to that field and the button does not render: noResults: function () {
return 'No results found TEST <button type="button">Click Me!</button>';
}, Copying the whole file just to be able to modify one function does not seem like the best way to achieve this. And also since the button does not render it proves that it is not the correct way either. What would be the proper way to achieve this? Thank you, Azegas |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Apparently I had to return a jQuery object instead, so that Select2 would correctly render the button as HTML. such works, renders a HTML button instead of simply displaying text: noResults: function () {
return $('<div>No results found <a href="/admin/vessel/vessel/add/" style="color:red;">Add vessel</a></div>');
}, Now the goal is not to have THE WHOLE |
Beta Was this translation helpful? Give feedback.
-
Asked here as well - https://forums.select2.org/t/how-do-i-rename-the-noresults-function-message/2531 |
Beta Was this translation helpful? Give feedback.
-
Hi there 👋, The message can't over overridden via the configuration. You will have to provide your own translation file with the correct new message. This repo is really only concerned with the Django integration of Select2. If you want to know how to create a translation file, the Select2 community is certainly the best place to ask. Please let me know, should you have any further questions. Best, |
Beta Was this translation helpful? Give feedback.
Scratch that, I found a test in the JS code that should allow you to override a single message, see also: https://github.com/select2/select2/blob/07bd61a0e8b928d490c86f61d6abbdcb61f4bbd4/tests/options/translation-tests.js#L63-L87
Just pass the following options: