Don't display non-unique field error if field name is empty

This commit is contained in:
silverpill 2022-10-31 18:23:17 +00:00
parent fe58af883d
commit e0137cd541

View file

@ -65,7 +65,7 @@
</a> </a>
</div> </div>
<button <button
v-if="form.fields_attributes.length <= extraFieldMaxCount" v-if="canAddExtraField()"
type="button" type="button"
class="add-extra-field" class="add-extra-field"
@click="addExtraField()" @click="addExtraField()"
@ -174,7 +174,7 @@ function isValidExtraField(index: number): boolean {
const field = form.fields_attributes[index] const field = form.fields_attributes[index]
for (let prevIndex = 0; prevIndex < index; prevIndex++) { for (let prevIndex = 0; prevIndex < index; prevIndex++) {
const prevField = form.fields_attributes[prevIndex] const prevField = form.fields_attributes[prevIndex]
if (field.name === prevField.name) { if (field.name && field.name === prevField.name) {
// Label is not unique // Label is not unique
return false return false
} }
@ -186,6 +186,10 @@ function removeExtraField(index: number) {
form.fields_attributes.splice(index, 1) form.fields_attributes.splice(index, 1)
} }
function canAddExtraField(): boolean {
return form.fields_attributes.length <= extraFieldMaxCount
}
function addExtraField() { function addExtraField() {
form.fields_attributes.push({ name: "", value: "", value_source: "" }) form.fields_attributes.push({ name: "", value: "", value_source: "" })
} }