Skip to content

Commit ee0f8a1

Browse files
committed
Do not confuse the JS when fields are on the same line
1 parent 319a49f commit ee0f8a1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

content_editor/static/content_editor/content_editor.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
orderMachine.append(inlines)
400400

401401
inlines.each(function () {
402-
const ordering = $(".field-ordering input", this).val() || 1e9
402+
const ordering = $(".order-machine-ordering", this).val() || 1e9
403403
this.style.order = ordering
404404
ensureDraggable($(this))
405405
})
@@ -506,7 +506,7 @@
506506
return
507507

508508
const select = buildDropdown(regions)
509-
const regionInput = $inline.find(".field-region input")
509+
const regionInput = $inline.find(".order-machine-region")
510510

511511
select.className = "inline_move_to_region"
512512
select.value = regionInput.val()
@@ -528,7 +528,7 @@
528528
const $this = $(this)
529529
// Try input first and fall back to the readonly presentation
530530
let region =
531-
$this.find(".field-region input").val() ||
531+
$this.find(".order-machine-region").val() ||
532532
$this.find(".field-region .readonly").text()
533533

534534
if (!ContentEditor.regionsByKey[region]) {
@@ -552,20 +552,20 @@
552552

553553
function setBiggestOrdering($row) {
554554
const orderings = []
555-
orderMachine.find(".field-ordering input").each(function () {
555+
orderMachine.find(".order-machine-ordering").each(function () {
556556
if (!Number.isNaN(+this.value)) orderings.push(+this.value)
557557
})
558558
const ordering = 10 + Math.max.apply(null, orderings)
559-
$row.find(".field-ordering input").val(ordering)
559+
$row.find(".order-machine-ordering").val(ordering)
560560
$row.css("order", ordering)
561561
}
562562

563563
function insertAdjacent(row, inline, after = false) {
564-
const inlineOrdering = +qs(".field-ordering input", inline).value
564+
const inlineOrdering = +qs(".order-machine-ordering", inline).value
565565
const beforeRows = []
566566
const afterRows = []
567567
orderMachine.find(".inline-related:not(.empty-form)").each(function () {
568-
const thisOrderingField = qs(".field-ordering input", this)
568+
const thisOrderingField = qs(".order-machine-ordering", this)
569569
if (this !== row && !Number.isNaN(+thisOrderingField.value)) {
570570
if (
571571
after
@@ -581,7 +581,7 @@
581581
beforeRows.sort((a, b) => a[1].value - b[1].value)
582582
afterRows.sort((a, b) => a[1].value - b[1].value)
583583
let rows = [].concat(beforeRows)
584-
rows.push([row, qs(".field-ordering input", row)])
584+
rows.push([row, qs(".order-machine-ordering", row)])
585585
rows = rows.concat(afterRows)
586586
for (let i = 0; i < rows.length; ++i) {
587587
const thisRow = rows[i]
@@ -657,7 +657,7 @@
657657
// Not one of our managed inlines?
658658
if (!ContentEditor.pluginsByPrefix[prefix]) return
659659

660-
$row.find(".field-region input").val(ContentEditor.currentRegion)
660+
$row.find(".order-machine-region").val(ContentEditor.currentRegion)
661661
$row.find("h3 .inline_label").text(ContentEditor.messages.newItem)
662662
$row.attr("data-region", ContentEditor.currentRegion)
663663

@@ -811,6 +811,14 @@
811811
const span = document.createElement("span")
812812
span.className = "order-machine-insert-target"
813813
inline.appendChild(span)
814+
815+
// Be extra careful because multiple fields could be on one line
816+
qs(`.field-ordering input[name$="-ordering"]`, inline).classList.add(
817+
"order-machine-ordering",
818+
)
819+
qs(`.field-region input[name$="-region"]`, inline).classList.add(
820+
"order-machine-region",
821+
)
814822
}
815823

816824
$(document)
@@ -889,7 +897,7 @@
889897
region: ContentEditor.currentRegion,
890898
scrollY: window.scrollY,
891899
collapsed: qsa(
892-
".order-machine .inline-related.collapsed:not(.empty-form) .field-ordering input",
900+
".order-machine .inline-related.collapsed:not(.empty-form) .order-machine-ordering",
893901
).map((input) => input.value),
894902
})
895903
}
@@ -905,7 +913,7 @@
905913
".order-machine .inline-related:not(.empty-form)",
906914
)) {
907915
const collapsed = state.collapsed.includes(
908-
qs(".field-ordering input", inline).value,
916+
qs(".order-machine-ordering", inline).value,
909917
)
910918
/* XXX handle sections */
911919
inline.classList.toggle(

0 commit comments

Comments
 (0)