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