input-pill: Disable input of commas with invalid pills.

A user should not be able to start forming a new pill if the previous
pill is invalid.
This commit is contained in:
Brock Whittaker
2017-11-13 13:07:49 -08:00
committed by Tim Abbott
parent 4cd25fb861
commit bee0fa4001

View File

@@ -6,6 +6,7 @@ var input_pill = function ($parent) {
BACKSPACE: 8, BACKSPACE: 8,
LEFT_ARROW: 37, LEFT_ARROW: 37,
RIGHT_ARROW: 39, RIGHT_ARROW: 39,
COMMA: 188,
}; };
// a stateful object of this `pill_container` instance. // a stateful object of this `pill_container` instance.
@@ -303,6 +304,21 @@ var input_pill = function ($parent) {
store.$parent.find(".pill").last().focus(); store.$parent.find(".pill").last().focus();
} }
} }
// users should not be able to type a comma if the last field doesn't
// validate.
if (char === KEY.COMMA) {
// if the pill is successful, it will create the pill and clear
// the input.
if (funcs.appendPill(store.$input.text().trim()) !== false) {
funcs.clear(store.$input[0]);
// otherwise it will prevent the typing of the comma because they
// cannot add another pill until this input is valid.
} else {
e.preventDefault();
return;
}
}
}); });
// handle events while hovering on ".pill" elements. // handle events while hovering on ".pill" elements.