Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

v9.3.6 Select2 Support


Hello, are you considering adding KTU Select2 support in version 9.3.6?
I'm using an external browser, but I'm having problems with the CSS.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


Hi Halil

KTUI Select supports accessing custom data from selected options.
The native HTML title attribute works with KTUI Select, similar to Select2. You can set it on options and access it via JavaScript:

For Static Options:

<select

data-kt-select
data-kt-select-allow-clear="true"
>
<option value="1" title="Additional title data">Option 1</option>
<option value="2" title="Another title">Option 2</option>
</select>


For Remote/AJAX Data:

function Etkinlik_Genel_IslemDurumuListesi() {
const selectElement = document.getElementById("SLC_EtkinlikIslemDurumuBilgisi");

// Initialize KTUI Select with remote data
const select = KTSelect.getInstance(selectElement) || new KTSelect(selectElement);

// Listen for when options are loaded/updated
selectElement.addEventListener("change", function() {
const selectedOption = this.options[this.selectedIndex];
const title = selectedOption.title || selectedOption.getAttribute("title");

// Use the title data (e.g., update TinyMCE)
if (tinymce.get("TXA_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi")) {
const currentContent = tinymce.get("TXA_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi").getContent();
tinymce.get("TXA_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi")
.setContent(currentContent + title);
}
});

// If using remote data, you may need to set title attributes after data loads
// This can be done via a custom event listener or by modifying the remote data handler
}


Currently, KTUI Select's remote data handler extracts only id and title from your Controller response. To preserve additional fields like color, you have two options:
Set the title attribute manually after options are created (recommended for simple cases)
Modify the remote data mapping to preserve additional fields (requires custom code)
For your specific use case with remote data returning color and title, I recommend using the native title attribute approach, as it's the simplest and most compatible with your existing Select2 code pattern.



Hi Halil İbrahim AYHAN,

Could you please give more detailed requirements or a reference from select2 for this feature? We will consider adding it for KTUI Select.

Thanks



Hi,
Currently, with Select2, I'm returning additional fields called color and title from the Controller.


function Etkinlik_Genel_IslemDurumuListesi() {
$("#SLC_EtkinlikIslemDurumuBilgisi").select2({
allowClear: true,
ajax: {
url: "/Etkinlik/Genel/IslemDurumuListesi_Alan2",
type: "GET",
delay: 250,
data: function (Deger) {
return {
AramaBilgisi: Deger.term
};
},
processResults: function (GelenVeri) {
return {
results: GelenVeri
};
}
},
templateResult: SelectOption_GenelBicimlendirme
});
}

function SelectOption_GenelBicimlendirme(Nesne) {
if (!Nesne.id) {
return Nesne.text;
}

var $Sonuc = $("<span >" + Nesne.text + "</span>");
return $Sonuc;
}



tinymce.get("TXA_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi").setContent(tinymce.get("TXA_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi").getContent() + $("#SLC_KararBilgisiTanimlamaPencereAlani_AciklamaBilgisi option:selected")[0].title);



I can perform data transfer using the title in Select2, but this feature is not available in KTUI Select.



Hi,

Metronic 9.x uses KTUI Select instead of Select2:
https://ktui.io/docs/select


Regards,
Sean


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(