diff --git a/src/components/GrampsjsFormSelectDate.js b/src/components/GrampsjsFormSelectDate.js index 7a23bc47..3fff2b5d 100644 --- a/src/components/GrampsjsFormSelectDate.js +++ b/src/components/GrampsjsFormSelectDate.js @@ -8,7 +8,7 @@ import '@material/mwc-select' import '@material/mwc-list/mwc-list-item' import {sharedStyles} from '../SharedStyles.js' -import {getSortval} from '../util.js' +import {getSortval, dateIsEmpty} from '../util.js' import {GrampsjsTranslateMixin} from '../mixins/GrampsjsTranslateMixin.js' const modifiers = { @@ -494,6 +494,10 @@ class GrampsjsFormSelectDate extends GrampsjsTranslateMixin(LitElement) { return true } + isEmpty() { + return dateIsEmpty(this.data) + } + _openDatePicker1() { this.renderRoot.getElementById('input-date1').showPicker() } diff --git a/src/util.js b/src/util.js index db0836ec..d50131b0 100644 --- a/src/util.js +++ b/src/util.js @@ -577,3 +577,20 @@ export function clickKeyHandler(event) { event.stopPropagation() } } + +export function dateIsEmpty(date) { + if (date.modifier === 6) { + // Text Only Date is never empty + return false + } + if (JSON.stringify(date.dateval.slice(0, 4)) !== '[0,0,0,false]') { + return false + } + if ( + date.dateval.len > 4 && + JSON.stringify(date.dateval.slice(4)) !== '[0,0,0,false]' + ) { + return false + } + return true +} diff --git a/src/views/GrampsjsViewNewPerson.js b/src/views/GrampsjsViewNewPerson.js index 8a24ffcd..f93db0f9 100644 --- a/src/views/GrampsjsViewNewPerson.js +++ b/src/views/GrampsjsViewNewPerson.js @@ -4,7 +4,7 @@ import {GrampsjsViewNewObject} from './GrampsjsViewNewObject.js' import '../components/GrampsjsFormName.js' import '../components/GrampsjsFormPrivate.js' import '../components/GrampsjsFormSelectObjectList.js' -import {makeHandle} from '../util.js' +import {makeHandle, dateIsEmpty} from '../util.js' import {apiPost} from '../api.js' const gender = { @@ -135,8 +135,8 @@ export class GrampsjsViewNewPerson extends GrampsjsViewNewObject { const birthString = this.translateTypeName(false, 'event_types', 'Birth') const deathString = this.translateTypeName(false, 'event_types', 'Death') const {birth, death, ...person} = this.data - const hasBirth = birth.place || birth?.date?._class - const hasDeath = death.place || death?.date?._class + const hasBirth = birth.place || (birth?.date && !dateIsEmpty(birth.date)) + const hasDeath = death.place || (death?.date && !dateIsEmpty(birth.date)) if (!hasBirth && !hasDeath) { return [person] }