Skip to content

Commit

Permalink
Bugfix/tags remember choices on edit idea (#389)
Browse files Browse the repository at this point in the history
* added forgotten groupedTags from cache

* Clean up test code

* Added fallback when choosing static form with dynamic fields
  • Loading branch information
LorenzoJokhan authored Apr 13, 2023
1 parent 8846a68 commit e928524
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/cms/lib/modules/openstad-pages/lib/load-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = function (req, res, next) {

if (Array.isArray(tags)) {
req.data.openstadTags = tags;
req.data.groupedOpenstadTags = _.groupBy(tags, function(tag){return tag.type});

next();
} else if(retrievedEmpty) {
req.data.openstadTags = [];
Expand Down
6 changes: 6 additions & 0 deletions packages/cms/lib/modules/resource-form-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ module.exports = {
const isReactedTo = activeResource ? (activeResource.yes > 0 || activeResource.no > 0 || activeResource.argumentCount > 0) : false;
const isOwnerOrAdmin = ((!isReactedTo || !widget.hideAdminAfterPublicAction) && isOwner) || req.data.hasModeratorRights;


widget.isTagSelected = function(tagId) {
if(!activeResource || !Array.isArray(activeResource.tags)) return false;
return activeResource.tags.findIndex(t => t.id === tagId) !== -1;
}

widget.mapConfig = self.getMapConfigBuilder(globalData)
.setDefaultSettings({
mapCenterLat: (activeResource && activeResource.location && activeResource.location.coordinates && activeResource.location.coordinates[0]) || globalData.mapCenterLat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ $(document).ready(function () {

$(form).find('input[type="submit"]').each(function(index, button) {
oldButtonValues.push($(this).val());

if(button.id === "btnSaveAsConcept" && publishField.val()) {
$(this).val('Verzenden...');
} else if(!publishField.val()) {
Expand All @@ -206,6 +205,12 @@ $(document).ready(function () {
success:function(response) {
formHasChanged = false;
var redirect = $(form).find('.form-redirect-uri').val();

// for some reason when you select the dynamic form then the input field with class .form-redirect-uri is not within the form
if(!redirect) {
redirect = document.querySelector('.form-redirect-uri').value;
}

redirect = redirect.replace(':id', response.id);
redirect = window.siteUrl + redirect;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
{% endfor %}
{% endif %}
</div>


{% if field.tagType === '' or field.tagType === undefined %}
{% for key, tagList in data.groupedOpenstadTags %}
{% set outer_loop = loop %}
Expand All @@ -42,7 +42,7 @@
value="{{tag.id}}"
id="checkbox-{{outer_loop.index}}-{{loop.index}}-{{tag.id}}"
{% if field.fieldRequired %}required{% endif %}
{% if field.idea.tags %}checked{% endif %}
{% if data.widget.isTagSelected(tag.id) %}checked{% endif %}
/>
<label for="checkbox-{{outer_loop.index}}-{{loop.index}}-{{tag.id}}" class="checkbox-label">{{tag.name}}</label>
</div>
Expand Down

1 comment on commit e928524

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Published new image: openstad/frontend:development-e928524

Please sign in to comment.