From b87475fa29ae1856da66f59691bccaefcce55fa7 Mon Sep 17 00:00:00 2001 From: Jesse Dunietz Date: Sun, 22 May 2016 00:52:42 -0400 Subject: [PATCH 1/3] Prevented default values from getting submitted for attributes that are inapplicable to the current entity/event type. --- client/src/annotator_ui.js | 55 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/client/src/annotator_ui.js b/client/src/annotator_ui.js index b3afe214f..0be2c46fc 100644 --- a/client/src/annotator_ui.js +++ b/client/src/annotator_ui.js @@ -72,7 +72,7 @@ var AnnotatorUI = (function($, window, undefined) { // utility function, originally for stripping numerix suffixes // from arc types (e.g. "Theme2" -> "Theme"). For values // without suffixes (including non-strings), returns given value. - if (typeof(s) != "string") { + if (typeof(s) != "string") { return s; // can't strip } var m = s.match(/^(.*?)(\d*)$/); @@ -128,7 +128,7 @@ var AnnotatorUI = (function($, window, undefined) { // in rapid annotation mode, prioritize the keys 0..9 for the // ordered choices in the quick annotation dialog. - if (Configuration.rapidModeOn && rapidAnnotationDialogVisible && + if (Configuration.rapidModeOn && rapidAnnotationDialogVisible && "0".charCodeAt() <= code && code <= "9".charCodeAt()) { var idx = String.fromCharCode(code); var $input = $('#rapid_span_'+idx); @@ -602,7 +602,7 @@ var AnnotatorUI = (function($, window, undefined) { eLeft = Math.min(Math.max(eLeft,0), screenWidth - elementWidth); } else { eLeft = 0; - } + } if (screenHeight > elementHeight) { eTop = Math.min(Math.max(eTop,0), screenHeight - elementHeight); } else { @@ -672,7 +672,7 @@ var AnnotatorUI = (function($, window, undefined) { } $('#span_selected').text(spanText); - var encodedText = encodeURIComponent(spanText); + var encodedText = encodeURIComponent(spanText); $.each(searchConfig, function(searchNo, search) { $('#span_'+search[0]).attr('href', search[1].replace('%s', encodedText)); }); @@ -880,8 +880,15 @@ var AnnotatorUI = (function($, window, undefined) { var shownCount = 0; $.each(attrTypes, function(attrNo, attr) { var $input = $('#'+category+'_attr_'+Util.escapeQuotes(attr.type)); - var showAttr = showAllAttributes || $.inArray(attr.type, validAttrs) != -1; - if (showAttr) { + var attrIsApplicable = $.inArray(attr.type, validAttrs) != -1; + + if (attrIsApplicable) { + $input.val(attr.default).change(); // reset form value to default + } else { + $input.val('').change(); // clear form value to avoid submitting inapplicable default value + } + + if (showAllAttributes || attrIsApplicable) { // $input.button('widget').parent().show(); $input.closest('.attribute_type_label').show(); shownCount++; @@ -895,12 +902,12 @@ var AnnotatorUI = (function($, window, undefined) { showValidAttributes = function() { var type = $('#span_form input:radio:checked').val(); - + showAllAttributes = false; - + var entityAttrCount = showAttributesFor(entityAttributeTypes, 'entity', type); var eventAttrCount = showAttributesFor(eventAttributeTypes, 'event', type); - + // show attribute frames only if at least one attribute is // shown, and set size classes appropriately if (eventAttrCount > 0) { @@ -975,7 +982,7 @@ var AnnotatorUI = (function($, window, undefined) { var $label = $('