From f4252ed9cd837b0c2f210955896736863002e4d8 Mon Sep 17 00:00:00 2001 From: miftahurrahmi Date: Tue, 21 Nov 2023 14:58:39 +0700 Subject: [PATCH] fix datatype datetime,date,time --- src/Controllers/Controller.php | 32 +++++++++++++------ .../badaso/pages/crud-generated/edit.vue | 16 +++++++--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/Controllers/Controller.php b/src/Controllers/Controller.php index bc1aa291..5bc3c558 100644 --- a/src/Controllers/Controller.php +++ b/src/Controllers/Controller.php @@ -135,19 +135,31 @@ public function getContentByType($data_type, $data_row, $value) $return_value = $value; break; case 'time': - $z_removed = explode('.', $value)[0]; - $time = explode('T', $z_removed)[1]; - $return_value = $time; + if($value == null){ + $return_value = $value; + }else{ + $z_removed = explode('.', $value)[0]; + $time = explode('T', $z_removed)[1]; + $return_value = $time; + } break; case 'date': - $z_removed = explode('.', $value)[0]; - $date = explode('T', $z_removed)[0]; - $return_value = $date; + if ($value == null) { + $return_value = $value; + } else{ + $z_removed = explode('.', $value)[0]; + $date = explode('T', $z_removed)[0]; + $return_value = $date; + } break; case 'datetime': - $z_removed = explode('.', $value)[0]; - $date_time = str_replace('T', ' ', $z_removed); - $return_value = $date_time; + if ($value == null) { + $return_value = $value; + } else{ + $z_removed = explode('.', $value)[0]; + $date_time = str_replace('T', ' ', $z_removed); + $return_value = $date_time; + } break; case 'select': $return_value = $value; @@ -569,7 +581,7 @@ public function updateData($data, $data_type) } if (in_array($data_row->type, [ - 'number', + 'number', 'datetime', 'date', 'time', ])) { $new_data[$key] = $this->getContentByType($data_type, $data_row, $value) !== null ? $this->getContentByType($data_type, $data_row, $value) : null; } else { diff --git a/src/resources/badaso/pages/crud-generated/edit.vue b/src/resources/badaso/pages/crud-generated/edit.vue index 6a107f26..c7c12db9 100644 --- a/src/resources/badaso/pages/crud-generated/edit.vue +++ b/src/resources/badaso/pages/crud-generated/edit.vue @@ -501,15 +501,23 @@ export default { data.value = parseInt( this.record[this.$caseConvert.stringSnakeToCamel(data.field)] ); - } else if (data.type == "datetime" || data.type == "date") { - const dateValue = this.record[ - this.$caseConvert.stringSnakeToCamel(data.field) + } else if(data.type == "datetime"){ + data.value = this.record[ + this.$caseConvert.stringSnakeToCamel(data.field) + ] + ? this.record[ + this.$caseConvert.stringSnakeToCamel(data.field) + ].replace(" ", "T") + : null; + } else if(data.type == "date"){ + var val = this.record[ + this.$caseConvert.stringSnakeToCamel(data.field) ] ? this.record[ this.$caseConvert.stringSnakeToCamel(data.field) ].replace(" ", "T") : null; - data.value = new Date(dateValue); + data.value = val !== null ? new Date(val) : val; } else if (data.value == undefined && data.type == "hidden") { data.value = data.details.value ? data.details.value : ""; } else if (