wip: conditional mandatory body dimensions
This commit is contained in:
@@ -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++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user