Skip to content

Commit

Permalink
fix boolean to default to false upon deserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
tintinthong committed Mar 7, 2024
1 parent 61e766e commit 5e5e539
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/base/boolean.gts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
Component,
useIndexBasedKey,
FieldDef,
BaseDefConstructor,
BaseInstanceType,
deserialize,
} from './card-api';
import { fn } from '@ember/helper';
import { RadioInput } from '@cardstack/boxel-ui/components';
Expand Down Expand Up @@ -33,6 +36,17 @@ export default class BooleanField extends FieldDef {
static [serialize](val: any) {
return Boolean(val);
}

static async [deserialize]<T extends BaseDefConstructor>(
this: T,
val: any,
): Promise<BaseInstanceType<T>> {
if (val === undefined || val === null) {
return false as BaseInstanceType<T>;
}
return Boolean(val) as BaseInstanceType<T>;
}

static [queryableValue](val: any): boolean {
if (typeof val === 'string') {
return val.toLowerCase() === 'true';
Expand Down Expand Up @@ -62,14 +76,13 @@ export default class BooleanField extends FieldDef {
</template>

private items = [
{ id: 'true', value: true, text: 'True' },
{ id: 'false', value: false, text: 'False' },
{ id: 'true', value: true, text: 'True' },
];

private radioGroup = `__cardstack_bool${groupNumber++}__`;

get checkedId() {
console.log(this.args.model);
return this.args.model === undefined || this.args.model === null
? 'false'
: String(this.args.model);
Expand Down

0 comments on commit 5e5e539

Please sign in to comment.