Skip to content

Commit 54459ff

Browse files
committed
form.field.Text: emptyValue config #4953
1 parent defedcb commit 54459ff

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/form/field/Text.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class Text extends Base {
7575
* @member {String[]|null} disabledChars_=null
7676
*/
7777
disabledChars_: null,
78+
/**
79+
* Configure the value of empty fields. null or an empty string is recommended.
80+
* @member {String|null} emptyValue=null
81+
*/
82+
emptyValue: null,
7883
/**
7984
* @member {String|null} error_=null
8085
*/
@@ -950,6 +955,21 @@ class Text extends Base {
950955
return value
951956
}
952957

958+
/**
959+
* Triggered before the value config gets changed
960+
* @param {String|null} value
961+
* @param {String|null} oldValue
962+
* @returns {String|null}
963+
* @protected
964+
*/
965+
beforeSetValue(value, oldValue) {
966+
if (value === null || value === '') {
967+
return this.emptyValue
968+
}
969+
970+
return value
971+
}
972+
953973
/**
954974
* Resets the field to its original value or null depending on the clearToOriginalValue config
955975
*/

0 commit comments

Comments
 (0)