wip: conditional mandatory body dimensions

This commit is contained in:
Björn Fromme
2025-07-25 21:47:00 +02:00
parent 9c5597eb23
commit b992e4a5ea
6 changed files with 207 additions and 10 deletions
@@ -1,23 +1,23 @@
import { Controller } from '@hotwired/stimulus'
import {Controller} from '@hotwired/stimulus'
export default class extends Controller {
static targets = [ 'fields', 'field', 'addButton', 'index' ]
static targets = ['fields', 'field', 'addButton', 'index']
static values = {
prototype: String,
maxItems: Number,
itemsCount: Number,
}
connect () {
this.index = this.itemsCountValue = this.fieldTargets.length
connect() {
this.itemsCountValue = this.fieldTargets.length
}
addItem() {
let prototype = JSON.parse(this.prototypeValue)
const newField = prototype.replace(/__name__/g, this.index)
const index = this.fieldTargets.length + 1
const prototype = JSON.parse(this.prototypeValue)
const newField = prototype.replace(/__name__/g, index)
this.fieldsTarget.insertAdjacentHTML('beforeend', newField)
this.index++
this.itemsCountValue++
}