Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot in key inside key-value field #15072

Closed
wants to merge 8 commits into from
12 changes: 8 additions & 4 deletions packages/forms/resources/js/components/key-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ export default function keyValueFormComponent({ state }) {

this.updateState()
},

escapeString: function (string) {
return String(string).replace(/\./g, '\.');
},
reorderRows: function (event) {
const rows = Alpine.raw(this.rows)

this.rows = []

const reorderedRow = rows.splice(event.oldIndex, 1)[0]
rows.splice(event.newIndex, 0, reorderedRow)

Expand All @@ -81,6 +82,8 @@ export default function keyValueFormComponent({ state }) {
let rows = []

for (let [key, value] of Object.entries(this.state ?? {})) {
key = this.escapeString(key)
value = this.escapeString(value)
rows.push({
key,
value,
Expand All @@ -98,9 +101,10 @@ export default function keyValueFormComponent({ state }) {
return
}

state[row.key] = row.value
state[this.escapeString(row.key)] = this.escapeString(row.value)
})


// This is a hack to prevent the component from updating rows again
// after a state update, which would otherwise be done by the `state`
// watcher. If rows are updated again, duplicate keys are removed.
Expand All @@ -109,6 +113,6 @@ export default function keyValueFormComponent({ state }) {
this.shouldUpdateRows = false

this.state = state
},
}
}
}