Skip to content

Commit

Permalink
Fixes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Aug 2, 2024
1 parent 3297e5e commit bb044e6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/assets/javascripts/article-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,13 @@ class ArticleForm {
}

prepareRatioDataForSequentialRepresentation() {
const numberOfRatios = $(`input[name^="${this.unitFieldsNamePrefix}[article_unit_ratios_attributes]"][name$="[quantity]"]`).length;
const indices = $(`input[name^="${this.unitFieldsNamePrefix}[article_unit_ratios_attributes]"][name$="[quantity]"]`)
.toArray()
.map((field) => parseInt(field.name.replace(/.+\[([0-9]+)\]\[quantity\]/, '$1')));
const maxIndex = Math.max(...indices);
const minIndex = Math.min(...indices);

for (let i = numberOfRatios; i > 1; i--) {
for (let i = maxIndex; i > minIndex; i--) {
const currentField$ = $(`input[name="${this.ratioQuantityFieldNameByIndex(i)}"]`, this.articleForm$);
const currentValue = currentField$.val();
const previousValue = $(`input[name="${this.ratioQuantityFieldNameByIndex(i - 1)}"]:last`, this.articleForm$).val();
Expand Down

0 comments on commit bb044e6

Please sign in to comment.