Skip to content

Commit

Permalink
Changing clear element atom to be W3C compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Mar 6, 2018
1 parent 9c0ca98 commit b436822
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,25 @@ bot.action.clear = function(element) {
'Element must be user-editable in order to clear it.');
}

bot.action.LegacyDevice_.focusOnElement(element);
if (element.value) {
bot.action.LegacyDevice_.focusOnElement(element);
element.value = '';
bot.events.fire(element, bot.events.EventType.CHANGE);
bot.events.fire(element, bot.events.EventType.BLUR);
bot.action.LegacyDevice_.focusOnElement(document.body);
} else if (bot.dom.isElement(element, goog.dom.TagName.INPUT) &&
(element.getAttribute('type') && element.getAttribute('type').toLowerCase() == "number")) {
// number input fields that have invalid inputs
// report their value as empty string with no way to tell if there is a
// current value or not
bot.action.LegacyDevice_.focusOnElement(element);
element.value = '';
}

if (bot.dom.isContentEditable(element)) {
// A single space is required, if you put empty string here you'll not be
// able to interact with this element anymore in Firefox.
bot.action.LegacyDevice_.focusOnElement(element);
element.innerHTML = ' ';
// contentEditable does not generate onchange event.
}
Expand Down

0 comments on commit b436822

Please sign in to comment.