Skip to content

Commit

Permalink
Do not submit form if mic is blocked, see case 1 in Daniel-Hug#9
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-ivan committed Aug 23, 2017
1 parent 7219897 commit cba00d2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions speech-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

var talkMsg = 'Speak now';
// seconds to wait for more input after last
var defaultPatienceThreshold = 6;
var defaultPatienceThreshold = 6;

function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
Expand All @@ -19,6 +19,7 @@
var patience = parseInt(inputEl.dataset.patience, 10) || defaultPatienceThreshold;
var micBtn, micIcon, holderIcon, newWrapper;
var shouldCapitalize = true;
var isError = false;

// gather inputEl data
var nextNode = inputEl.nextSibling;
Expand Down Expand Up @@ -100,12 +101,16 @@
if (oldPlaceholder !== null) inputEl.placeholder = oldPlaceholder;

// If the <input> has data-instant-submit and a value,
if (inputEl.dataset.instantSubmit !== undefined && inputEl.value) {
if (inputEl.dataset.instantSubmit !== undefined && inputEl.value && !isError) {
// submit the form it's in (if it is in one).
if (inputEl.form) inputEl.form.submit();
}
};

recognition.onerror = function (event) {
isError = true;
}

var finalTranscript = '';
recognition.onresult = function(event) {
clearTimeout(timeout);
Expand Down

0 comments on commit cba00d2

Please sign in to comment.