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

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(