Skip to content

Commit

Permalink
Merge pull request #968 from maykinmedia/feature/967-clear-toelichtin…
Browse files Browse the repository at this point in the history
…g-field

🐛 [#967] fixed bug that wouldn't clear toelichting field
  • Loading branch information
alextreme authored Aug 25, 2023
2 parents 82c0dee + 8c353a4 commit 9dce546
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/sdg/js/components/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ class GenericForm {
this.collapseExpand()
}

emptyFieldValues(fields) {
fields.forEach((item) => {
const textarea = item.querySelector("textarea");
textarea.value = ""
})
async emptyFieldValues(fields) {
if (await fields === []) {
fields.forEach((item) => {
const textarea = item.querySelector("textarea");
textarea.value = "";
})
}
}

async getProductTranslationName(productId, language) {
Expand All @@ -84,7 +86,6 @@ class GenericForm {
.then(data => data.results[0])

if (translationJsonResults) {

if (translationJsonResults.productTitel) {
return translationJsonResults.productTitel
}
Expand Down Expand Up @@ -141,9 +142,8 @@ class GenericForm {
let previousIndex = input.selectedIndex;

const displayFunc = async (displayDependency) => {
const controls = await displayDependency.querySelectorAll(".form__control")
if (input.selectedIndex === 2) {
const controls = displayDependency.querySelectorAll(".form__control")

if (input.selectedIndex != previousIndex) {
if (confirm("Weet u zeker dat u dit product niet aanbiedt?\nAls u 'OK' antwoordt worden alle teksten leeggemaakt.")) {
this.resetSpecefiekeGegevens();
Expand All @@ -163,25 +163,10 @@ class GenericForm {
}
});
} else {
const controls = displayDependency.querySelectorAll(".form__control")
let emptyOrDefault = 0
controls.forEach((element, index, array) => {
const textarea = element.querySelector("textarea");
const defaultExplanation = document.querySelector(`.form__reference-${element.lang}`).dataset.productAanwezigToelichting;

if (!textarea.value || textarea.value === defaultExplanation) {
emptyOrDefault += 1
}

if (emptyOrDefault == 2) {
this.displayHidden(dependency, "aanwezig")
this.emptyFieldValues([array[index - 1], element])
previousIndex = 0;
return
}

this.displayBlock(dependency, "aanwezig")
})
controls.forEach(async (fields) => {
this.displayHidden(dependency, "aanwezig");
this.emptyFieldValues(fields);
});
};

previousIndex = input.selectedIndex;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.18 on 2023-08-23 21:42

from django.db import migrations
from django.db.models import Q


def remove_unwanted_toelichting_fields(apps, schema_editor):
LocalizedProducts = apps.get_model("producten", "LocalizedProduct")
for LocalizedProduct in LocalizedProducts.objects.filter(
~Q(product_aanwezig_toelichting__exact="")
):
if (
LocalizedProduct.product_versie.product.product_aanwezig
or LocalizedProduct.product_versie.product.product_aanwezig is None
):
LocalizedProduct.product_aanwezig_toelichting = ""
LocalizedProduct.save()


class Migration(migrations.Migration):
dependencies = [
("producten", "0056_remove_localizedgeneriekproduct_slug"),
]

operations = [
migrations.RunPython(
remove_unwanted_toelichting_fields, migrations.RunPython.noop
),
]

0 comments on commit 9dce546

Please sign in to comment.