From 81bef0ca7b4ea145757f66063d7a9fddc1ef9631 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Thu, 19 Oct 2023 19:50:22 +0200 Subject: [PATCH] fixed regression on custom fields removal --- .../views/_components/editor/CustomFields.cfm | 32 ++++++++++++++++--- .../_components/editor/CustomFieldsHelper.cfm | 18 +++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFields.cfm b/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFields.cfm index b53d9689f9..f4e88a1fdf 100644 --- a/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFields.cfm +++ b/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFields.cfm @@ -5,16 +5,31 @@ the CB Helper: cb.quickCustomFields() or cb.getCustomField( key, [defaultValue] )

+
+ -
+ +
- + -
@@ -34,7 +49,7 @@ /> - + - +
diff --git a/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFieldsHelper.cfm b/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFieldsHelper.cfm index e55e58a092..f3785d040e 100644 --- a/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFieldsHelper.cfm +++ b/modules/contentbox/modules/contentbox-admin/views/_components/editor/CustomFieldsHelper.cfm @@ -3,11 +3,16 @@ 'use strict'; function customFieldsModel(){ return { + customFields : #toJSON( prc.oContent.getCustomFields().map( ( field ) => arguments.field.getMemento() ) )#, + isTemplatedField : field => window.assignedTemplate + && window.assignedTemplate.definition.customFields + && window.assignedTemplate.definition.customFields.value.some( item => item.name == field.key.trim() ), + customFieldTemplate : { "key" : "", "value" : "", "relatedContent" : "#prc.oContent.getContentID()#" }, + init(){ window.addCustomField = this.addCustomField; }, - customFields : #toJSON( prc.oContent.getCustomFields().map( ( field ) => arguments.field.getMemento() ) )#, - customFieldTemplate : { "key" : "", "value" : "", "relatedContent" : "#prc.oContent.getContentID()#" }, + addCustomField( key, value ){ // Alpine events if( key instanceof CustomEvent ){ @@ -21,6 +26,7 @@ function customFieldsModel(){ if( value ) newField.value = value; this.customFields.push( newField ); }, + cleanCustomFields(){ this.customFields.forEach( ( item, index ) => { if( !item.key.trim() ){ @@ -28,16 +34,14 @@ function customFieldsModel(){ } } ); }, + removeCustomField( field ){ let fieldIndex = this.customFields.findIndex( item => item.key.trim() == field.key.trim() ); if( fieldIndex > -1 ){ this.customFields.splice( fieldIndex, 1 ); } - }, - isTemplatedField : field => window.assignedTemplate - && window.assignedTemplate.definition.customFields - && window.assignedTemplate.definition.customFields.value.some( item => item.name == field.key.trim() ) + } } } - \ No newline at end of file +