Skip to content

Commit

Permalink
Add isoDate option for DateField class (#5183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniz Toprak authored Jan 15, 2024
1 parent 72a8bca commit 38ae096
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/form/field/Date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class DateField extends Picker {
* @member {String} errorTextInvalidDate='Not a valid date'
*/
errorTextInvalidDate: 'Not a valid date',
/**
* @member {Boolean} isoDate=false
*/
isoDate: false,
/**
* True to hide the DatePicker when selecting a day
* @member {Boolean} hidePickerOnSelect=false
Expand Down Expand Up @@ -158,6 +162,17 @@ class DateField extends Picker {
}
}

/**
* Triggered before the value config got changed
* @param {String} value
* @param {String} oldValue
* @protected
*/
beforeSetValue(value, oldValue) {
const val = super.beforeSetValue(value, oldValue);
return (this.isoDate && val) ? val.substring(0, 10) : val;
}

/**
* @returns {Neo.component.DateSelector}
*/
Expand All @@ -171,7 +186,13 @@ class DateField extends Picker {
getValue() {
let value = this.value;

return this.submitDateObject && value ? new Date(`${value}T00:00:00.000Z`) : value
if(this.submitDateObject && value) {
return new Date(`${value}T00:00:00.000Z`);
} else if(this.isoDate && value) {
return new Date(value).toISOString();
}

return value;
}

/**
Expand Down

0 comments on commit 38ae096

Please sign in to comment.