From c52dbf2ce0b11a0ce1de0af48e1ecfbc2abdad58 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 15 Jul 2016 17:16:38 +0200 Subject: [PATCH] (firewall, alias) hide already used aliases. closes https://github.com/opnsense/core/issues/1042 --- src/www/firewall_aliases_edit.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/www/firewall_aliases_edit.php b/src/www/firewall_aliases_edit.php index 6f1806607..8daa1559c 100644 --- a/src/www/firewall_aliases_edit.php +++ b/src/www/firewall_aliases_edit.php @@ -291,6 +291,29 @@ include("head.inc"); $(this).parent().parent().remove(); } } + + /** + * link alias typeahead to input, only return items not already on this form. + */ + function addFieldTypeAhead() { + $(".fld_detail").typeahead({ + source: document.all_aliases[$("#typeSelect").val()], + matcher: function(item){ + var used = false; + $(".fld_detail").each(function(){ + if (item == $(this).val()) { + used = true; + } + }); + if (used) { + return false; + } else { + return ~item.toLowerCase().indexOf(this.query) + } + } + }); + } + // add new detail record $("#addNew").click(function(){ // copy last row and reset values @@ -300,7 +323,7 @@ include("head.inc"); }); $(".act-removerow").click(removeRow); // link typeahead to new item - $(".fld_detail").typeahead({ source: document.all_aliases[$("#typeSelect").val()] }); + addFieldTypeAhead(); // link geoip list to new item $(".geoip_list").change(function(){ $(this).parent().find('input').val($(this).val()); @@ -364,7 +387,7 @@ include("head.inc"); break; } $(".fld_detail").typeahead("destroy"); - $(".fld_detail").typeahead({ source: document.all_aliases[$("#typeSelect").val()] }); + addFieldTypeAhead(); } $("#typeSelect").change(function(){