Skip to content

Commit

Permalink
Merge pull request #1390 from craftcms/bugfix/1387-entries-field-reta…
Browse files Browse the repository at this point in the history
…in-selected-entry-type

mapping page, entries field - retain selected type id
  • Loading branch information
angrybrad authored Feb 26, 2024
2 parents 4f39d42 + ef89ada commit 2166508
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/templates/_includes/fields/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@
{% endfor %}

{% if sources and sources[0] %}
<div class="element-group element-group-entrytype" data-items="{{ entryTypes|json_encode }}">
{% set selectedTypeId = hash_get(feed.fieldMapping, optionsPath ~ '.group.typeId') ?: '' %}
<div class="element-group element-group-entrytype" data-items="{{ entryTypes|json_encode }}" data-selectedTypeId="{{ selectedTypeId }}">
<span>{{ 'Type:'|t('feed-me') }}</span>

{{ forms.selectField({
name: 'options[group][typeId]',
class: '',
value: hash_get(feed.fieldMapping, optionsPath ~ '.group.typeId') ?: '',
value: selectedTypeId,
options: entryTypes['item_' ~ sources[0].id] ?? [],
}) }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/feedme/dist/FeedMe.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/feedme/dist/FeedMe.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/web/assets/feedme/src/js/feed-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ $(function () {
.parents('.field-extra-settings')
.find('.element-group-entrytype');
var sections = $container.data('items');
var selectedTypeId = $container.data('selectedtypeid');

// var sections = $(this).parents('.element-sub-group').data('items');
var entryType = 'item_' + $(this).val();
Expand All @@ -199,7 +200,14 @@ $(function () {
var newOptions = '';
$.each(entryTypes, function (index, value) {
if (index) {
newOptions += '<option value="' + index + '">' + value + '</option>';
newOptions +=
'<option value="' +
index +
'"' +
(index == selectedTypeId ? ' selected="selected"' : '') +
'>' +
value +
'</option>';
}
});

Expand Down

0 comments on commit 2166508

Please sign in to comment.