@@ -191,6 +191,12 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges {
191191 */
192192 public editingAuthority = false ;
193193
194+
195+ /**
196+ * Whether or not the free-text editing is enabled when scrollable dropdown or hierarchical vocabulary is used
197+ */
198+ public enabledFreeTextEditing = false ;
199+
194200 /**
195201 * Field group used by authority field
196202 * @type {UntypedFormGroup }
@@ -438,15 +444,23 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges {
438444 * Process the change of authority field value updating the authority key and confidence as necessary
439445 */
440446 onChangeAuthorityField ( event ) : void {
441- this . mdValue . newValue . value = event . value ;
442- if ( event . authority ) {
443- this . mdValue . newValue . authority = event . authority ;
444- this . mdValue . newValue . confidence = ConfidenceType . CF_ACCEPTED ;
447+ if ( event ) {
448+ this . mdValue . newValue . value = event . value ;
449+ if ( event . authority ) {
450+ this . mdValue . newValue . authority = event . authority ;
451+ this . mdValue . newValue . confidence = ConfidenceType . CF_ACCEPTED ;
452+ } else {
453+ this . mdValue . newValue . authority = null ;
454+ this . mdValue . newValue . confidence = ConfidenceType . CF_UNSET ;
455+ }
456+ this . confirm . emit ( false ) ;
445457 } else {
458+ // The event is undefined when the user clears the selection in scrollable dropdown
459+ this . mdValue . newValue . value = '' ;
446460 this . mdValue . newValue . authority = null ;
447461 this . mdValue . newValue . confidence = ConfidenceType . CF_UNSET ;
462+ this . confirm . emit ( false ) ;
448463 }
449- this . confirm . emit ( false ) ;
450464 }
451465
452466 /**
@@ -480,4 +494,17 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges {
480494 }
481495 }
482496
497+ /**
498+ * Toggles the free-text ediitng mode
499+ */
500+ toggleFreeTextEdition ( ) {
501+ if ( this . enabledFreeTextEditing ) {
502+ if ( this . getModel ( ) . value !== this . mdValue . newValue . value ) {
503+ // Reload the model to adapt it to the new possible value modified during free text editing
504+ this . initAuthorityProperties ( ) ;
505+ }
506+ }
507+ this . enabledFreeTextEditing = ! this . enabledFreeTextEditing ;
508+ }
509+
483510}
0 commit comments