@@ -222,6 +227,50 @@
value: false
},
+ /**
+ * Set to true to mark the input as required.
+ */
+ required: {
+ type: Boolean,
+ value: false
+ },
+
+ /**
+ * Set to true to auto-validate the input value when it changes.
+ */
+ autoValidate: {
+ type: Boolean,
+ value: false
+ },
+
+ /**
+ * The error message to display when the input is invalid.
+ */
+ errorMessage: {
+ type: String
+ },
+
+ /**
+ * A pattern to validate the input with.
+ */
+ pattern: {
+ type: String
+ },
+
+ /**
+ * Set this to specify the pattern.
+ */
+ allowedPattern: {
+ type: String
+ },
+ _autoValidate: {
+ type: Boolean,
+ value: false
+ },
+ _required: {
+ type: Boolean,
+ value: false
+ },
_selectedSuggestionId: {
type: Object,
observer: '_selectPaperItem'
@@ -246,6 +295,12 @@
};
}
+ connectedCallback() {
+ super.connectedCallback();
+ this._autoValidate = this.autoValidate;
+ this._required = this.required;
+ }
+
_isEmpty(item) {
return item.length > 0;
}
@@ -258,6 +313,8 @@
chipLabel: this._inputValue
}
}));
+ this.required = false;
+ this.autoValidate = false;
this._inputValue = '';
}
}
@@ -267,6 +324,11 @@
(this._inputValue == '' || this._inputValue == undefined)) {
this._removeLastItem();
}
+
+ if(this.items.length == 0) {
+ this.autoValidate = this._autoValidate;
+ this.required = this._required;
+ }
}
_onKeyEsc(event) {
@@ -329,6 +391,8 @@
_selectPaperItem(event) {
this._saveTag(event.model.item.text);
+ this.required = false;
+ this.autoValidate = false;
this._inputValue = '';
this._autocompleteClass = "hide";
this.$.paperInput.focus();
diff --git a/paper-chip-input.html b/paper-chip-input.html
index 6deb463..e5fc5f9 100644
--- a/paper-chip-input.html
+++ b/paper-chip-input.html
@@ -60,8 +60,8 @@
label="[[label]]"
allowed-pattern="[[allowedPattern]]"
pattern="[[pattern]]"
- required="[[required]]"
- auto-validate="[[autoValidate]]"
+ required$="[[required]]"
+ auto-validate$="[[autoValidate]]"
error-message="[[errorMessage]]">
@@ -155,7 +155,14 @@
type: Boolean,
value: false
},
-
+ _autoValidate: {
+ type: Boolean,
+ value: false
+ },
+ _required: {
+ type: Boolean,
+ value: false
+ },
/**
* The error message to display when the input is invalid.
*/
@@ -192,6 +199,12 @@
return this.$.paperInput.validate();
}
}
+
+ connectedCallback() {
+ super.connectedCallback();
+ this._autoValidate = this.autoValidate;
+ this._required = this.required;
+ }
_onKeyEnter() {
if (this._value != '' && this._value != undefined) {
@@ -201,17 +214,17 @@
chipLabel: this._value
}
}));
+ this.required = false;
+ this.autoValidate = false;
this._value = '';
}
}
_onKeyBackspace() {
- if (this.items.length != 0 &&
- (this._value == '' || this._value == undefined)) {
+ if (this.items.length != 0 && (this._value == '' || this._value == undefined)) {
this._removeLastItem();
- } else if (this.$.slot.assignedNodes().length > 0 &&
- (this._value == '' || this._value == undefined)) {
- var distributedNodes = this.$.slot.assignedNodes({
+ } else if (this.$.slot.assignedNodes().length > 0 && (this._value == '' || this._value == undefined)) {
+ let distributedNodes = this.$.slot.assignedNodes({
flatten: true
})
let lastPaperChipIndex = 0;
@@ -223,6 +236,11 @@
this._throwChipRemovedEvent(this.childNodes[lastPaperChipIndex].label);
this.removeChild(this.childNodes[lastPaperChipIndex]);
}
+
+ if(this.items.length == 0 && this.$.slot.assignedNodes().length == 0) {
+ this.autoValidate = this._autoValidate;
+ this.required = this._required;
+ }
}
_saveTag(name) {
@@ -232,7 +250,7 @@
}
_removeChip(event) {
- var index = this.items.indexOf(event.detail.chipLabel);
+ const index = this.items.indexOf(event.detail.chipLabel);
if (index != -1) {
this.splice('items', index, 1);
}