diff --git a/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js b/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js index 04c2e200f8..b42ba9dd98 100644 --- a/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js +++ b/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js @@ -179,18 +179,22 @@ ve.ui.MWMetaDialog.prototype.onClose = function ( action ) { } if ( this.defaultSortKeyChanged ) { - newDefaultSortKeyItemData = { - 'type': 'mwDefaultSort', - 'attributes': { 'content': this.defaultSortInput.getValue() } - }; - if ( currentDefaultSortKeyItem ) { - newDefaultSortKeyItem = new ve.dm.MWDefaultSortMetaItem( - ve.extendObject( {}, currentDefaultSortKeyItem.getElement(), newDefaultSortKeyItemData ) - ); - currentDefaultSortKeyItem.replaceWith( newDefaultSortKeyItem ); - } else { - newDefaultSortKeyItem = new ve.dm.MWDefaultSortMetaItem( newDefaultSortKeyItemData ); - this.metaList.insertMeta( newDefaultSortKeyItem ); + if ( this.defaultSortInput.getValue() !== '' ) { + newDefaultSortKeyItemData = { + 'type': 'mwDefaultSort', + 'attributes': { 'content': this.defaultSortInput.getValue() } + }; + if ( currentDefaultSortKeyItem ) { + newDefaultSortKeyItem = new ve.dm.MWDefaultSortMetaItem( + ve.extendObject( {}, currentDefaultSortKeyItem.getElement(), newDefaultSortKeyItemData ) + ); + currentDefaultSortKeyItem.replaceWith( newDefaultSortKeyItem ); + } else { + newDefaultSortKeyItem = new ve.dm.MWDefaultSortMetaItem( newDefaultSortKeyItemData ); + this.metaList.insertMeta( newDefaultSortKeyItem ); + } + } else if ( currentDefaultSortKeyItem ) { + currentDefaultSortKeyItem.remove(); } }