New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

Issue with KTSelect with Remote Data and selected value


The selected value is not show, the select is empty, this is my code:
<select id="nazione_id" name="nazione_id" class="kt-select " data-kt-select="true" data-kt-select-remote="true" data-kt-select-data-url=" data-kt-select-data-field-value="id" data-kt-select-data-field-text="text" data-kt-select-enable-search="true" data-kt-select-search-param="term" data-kt-select-search-min-length="2" data-kt-select-search-debounce="300" data-kt-select-debug="true" data-kt-select-placeholder="Cerca..." >
<option value="FR" selected>Francia</option>
</select>

and this is the select after initialization:
<select id="nazione_id" name="nazione_id" class="hidden" data-kt-select="true" data-kt-select-remote="true" data-kt-select-data-url=" data-kt-select-data-field-value="id" data-kt-select-data-field-text="text" data-kt-select-enable-search="true" data-kt-select-search-param="term" data-kt-select-search-min-length="2" data-kt-select-search-debounce="300" data-kt-select-debug="true" data-kt-select-placeholder="Cerca..." data-kt-select-initialized="true">

<option value="option-ilyitbfu7" data-kt-select-option-initialized="true">Option option-ilyitbfu7</option></select>


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 (1)


Hi

This is a known issue with KTSelect when using remote data. The problem occurs because KTSelect clears existing options when fetching remote data, but doesn't properly restore the pre-selected values.

Instead of using the native selected attribute, use the data-kt-select-pre-selected attribute:

<select name="nazione_id" class="kt-select" 
data-kt-select="true"
data-kt-select-remote="true"
data-kt-select-data-url="
data-kt-select-data-field-value="id"
data-kt-select-data-field-text="text"
data-kt-select-enable-search="true"
data-kt-select-search-param="term"
data-kt-select-search-min-length="2"
data-kt-select-search-debounce="300"
data-kt-select-debug="true"
data-kt-select-placeholder="Cerca..."
data-kt-select-pre-selected="FR">
</select>


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  :(