diff --git a/plugins/customfields/customfields.yaml b/plugins/customfields/customfields.yaml index 8392df2..7cafbcd 100644 --- a/plugins/customfields/customfields.yaml +++ b/plugins/customfields/customfields.yaml @@ -6,7 +6,7 @@ homepage: http://trendschau.net licence: No licence metatabs: - adamhall: + customfields: fields: myfield: type: customfields diff --git a/plugins/customfields/js/customfields.js b/plugins/customfields/js/customfields.js index 357e61e..be5a6f6 100644 --- a/plugins/customfields/js/customfields.js +++ b/plugins/customfields/js/customfields.js @@ -1,4 +1,4 @@ -Vue.component('tab-adamhall', { +Vue.component('tab-customfields', { props: ['saved', 'errors', 'formdata', 'schema'], template: '
' + '' + '' + - '
{{ fielderrors }}
' + - '
{{ description|translate }}
' + + '
{{ description|translate }}
' + + '
{{ errors[name] }}
' + + '
{{ fielderrors }}
' + '
' + '' + '
' + @@ -405,24 +405,42 @@ Vue.component('component-customfields', { methods: { update: function(value, name) { + this.fielderrors = false; + this.errors = false; FormBus.$emit('forminput', {'name': name, 'value': value}); }, updatePairKey: function(index,event) { this.value[index].key = event.target.value; - + var regex = /^[a-z0-9]+$/i; - if(regex.test(event.target.value)) - { - this.fielderrors = false; - delete this.value[index].keyerror; - this.update(this.value,this.name); - } - else + + if(!this.keyIsUnique(event.target.value,index)) { this.value[index].keyerror = 'red'; - this.fielderrors = 'Only alphanumeric for keys allowed'; + this.fielderrors = 'Error: The key already exists'; + return; } + else if(!regex.test(event.target.value)) + { + this.value[index].keyerror = 'red'; + this.fielderrors = 'Error: Only alphanumeric for keys allowed'; + return; + } + + delete this.value[index].keyerror; + this.update(this.value,this.name); + }, + keyIsUnique: function(keystring, index) + { + for(obj in this.value) + { + if( (obj != index) && (this.value[obj].key == keystring) ) + { + return false; + } + } + return true; }, updatePairValue: function(index, event) { @@ -432,11 +450,10 @@ Vue.component('component-customfields', { if(event.target.value == '' || regex.test(event.target.value)) { this.value[index].valueerror = 'red'; - this.fielderrors = 'No empty values or html tags are allowed'; + this.fielderrors = 'Error: No empty values or html tags are allowed'; } else { - this.fielderrors = false; delete this.value[index].valueerror; this.update(this.value,this.name); } @@ -456,6 +473,7 @@ Vue.component('component-customfields', { deleteField: function(index) { this.value.splice(index,1); + this.update(this.value,this.name); }, }, })