Error-status: function renaming, bug-fix for acceptDate/-Time
Renamed functions working with a predicate function, fixed bug in
acceptTime/acceptDate.
229903
diff --git a/eclipse-scout-core/src/form/fields/FormField.js b/eclipse-scout-core/src/form/fields/FormField.js
index 991ac72..5895a16 100644
--- a/eclipse-scout-core/src/form/fields/FormField.js
+++ b/eclipse-scout-core/src/form/fields/FormField.js
@@ -42,6 +42,9 @@
this.dropType = 0;
this.dropMaximumSize = dragAndDrop.DEFAULT_DROP_MAXIMUM_SIZE;
this.empty = true;
+ /**
+ * @type {Status}
+ */
this.errorStatus = null;
this.fieldStyle = FormField.DEFAULT_FIELD_STYLE;
this.gridData = null;
@@ -337,6 +340,18 @@
this.setErrorStatus(status);
}
+ /**
+ * Whether or not the error status is or has the given status type.
+ * @param statusType
+ * @returns {boolean}
+ */
+ containsStatus(statusType) {
+ if (!this.errorStatus) {
+ return false;
+ }
+ return this.errorStatus.containsStatus(statusType);
+ }
+
setSuppressStatus(suppressStatus) {
this.setProperty('suppressStatus', suppressStatus);
}
@@ -364,19 +379,19 @@
* @param {object} statusType
*/
removeErrorStatus(statusType) {
- this.removeErrorStatusPredicate(function(status) {
+ this.removeErrorStatusByPredicate(function(status) {
return status instanceof statusType;
});
}
- removeErrorStatusPredicate(predicate) {
+ removeErrorStatusByPredicate(predicate) {
var status = this._errorStatus();
if (!status) {
return;
}
- if (status.containsStatusPredicate(predicate)) {
+ if (status.containsStatusByPredicate(predicate)) {
var newStatus = status.clone();
- newStatus.removeAllStatusPredicate(predicate);
+ newStatus.removeAllStatusByPredicate(predicate);
// If no other status remains -> clear error status
if (newStatus.hasChildren()) {
this.setErrorStatus(newStatus);
diff --git a/eclipse-scout-core/src/form/fields/datefield/DateField.js b/eclipse-scout-core/src/form/fields/datefield/DateField.js
index 60e8c9c..b77be9a 100644
--- a/eclipse-scout-core/src/form/fields/datefield/DateField.js
+++ b/eclipse-scout-core/src/form/fields/datefield/DateField.js
@@ -79,6 +79,9 @@
PARSE_ERROR: -1
};
+ /**
+ * Predicate function to find a PARSE_ERROR.
+ */
static PARSE_ERROR_PREDICATE = function(status) {
return status.code === DateField.ErrorCode.PARSE_ERROR;
};
@@ -1010,20 +1013,24 @@
}
/**
- * Clears the time field if date field is empty before accepting the input
+ * Clears the time field if date field is empty before accepting the input.<br/>
+ * Don't delete invalid input from the time field.
*/
acceptDate() {
- if (this.hasTime && strings.empty(this.$dateField.val())) {
+ var invalid = this.containsStatus(ParsingFailedStatus);
+ if (this.hasTime && !invalid && strings.empty(this.$dateField.val())) {
this.$timeField.val('');
}
this.acceptInput();
}
/**
- * Clears the date field if time field is empty before accepting the input
+ * Clears the date field if time field is empty before accepting the input.<br/>
+ * Don't delete invalid input from the time field.
*/
acceptTime() {
- if (this.hasDate && strings.empty(this.$timeField.val())) {
+ var invalid = this.containsStatus(ParsingFailedStatus);
+ if (this.hasDate && !invalid && strings.empty(this.$timeField.val())) {
this.$dateField.val('');
}
this.acceptInput();
@@ -1633,7 +1640,7 @@
}
_removePredictErrorStatus() {
- this.removeErrorStatusPredicate(DateField.PARSE_ERROR_PREDICATE);
+ this.removeErrorStatusByPredicate(DateField.PARSE_ERROR_PREDICATE);
}
/**
diff --git a/eclipse-scout-core/src/status/Status.js b/eclipse-scout-core/src/status/Status.js
index aaa6a6c..c2c69e2 100644
--- a/eclipse-scout-core/src/status/Status.js
+++ b/eclipse-scout-core/src/status/Status.js
@@ -96,16 +96,19 @@
}
/**
+ * Note: we cannot 'overload' this function, because predicates and status-types are both functions,
+ * thus we cannot distinct them by type or instanceof.
+ *
* @param {object} statusType
* @return {boolean} whether or not this status contains a child with the give type
*/
containsStatus(statusType) {
- return this.containsStatusPredicate(function(status) {
+ return this.containsStatusByPredicate(function(status) {
return status instanceof statusType;
});
}
- containsStatusPredicate(predicate) {
+ containsStatusByPredicate(predicate) {
return this.asFlatList().some(predicate);
}
@@ -124,15 +127,15 @@
* @param {object} statusType
*/
removeAllStatus(statusType) {
- this.removeAllStatusPredicate(function(status) {
+ this.removeAllStatusByPredicate(function(status) {
return status instanceof statusType;
});
}
- removeAllStatusPredicate(predicate) {
+ removeAllStatusByPredicate(predicate) {
if (this.hasChildren()) {
this.children.forEach(function(status) {
- status.removeAllStatusPredicate(predicate);
+ status.removeAllStatusByPredicate(predicate);
});
var newChildren = this.children.filter(function(status) {
// when status is not deletable we must add it as child again, thus --> true