Skip to content

Commit

Permalink
Merge pull request #3272 from bettyblocks/fix/default-value-object-co…
Browse files Browse the repository at this point in the history
…mponents-PAGE-3610

Fix/default value object components page 3610
  • Loading branch information
ingmar-stipriaan authored Nov 2, 2023
2 parents 60d5f84 + bc241ad commit 127ed4c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/radioinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
let resolvedCurrentValue;

// set the value based on the selected property type (list, relational or object)
if (isListProperty || isObjectProperty) {
if (isObjectProperty) {
resolvedCurrentValue = JSON.stringify({ uuid: defaultValueText });
} else if (isListProperty) {
resolvedCurrentValue = defaultValueText;
} else if (isPropertyArray && !isObjectProperty) {
resolvedCurrentValue = parseInt(defaultValueText, 10) || '';
Expand Down
5 changes: 4 additions & 1 deletion src/components/selectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
} = modelProperty;

const isObjectProperty = kind === 'object' || kind === 'OBJECT';
const resolvedCurrentValue = defaultValueText || placeholderLabelText;

const resolvedCurrentValue = isObjectProperty
? JSON.stringify({ uuid: defaultValueText })
: defaultValueText || placeholderLabelText;

const [currentValue, setCurrentValue] = useState(resolvedCurrentValue);
B.defineFunction('Clear', () => setCurrentValue(''));
Expand Down
4 changes: 3 additions & 1 deletion src/prefabs/questionnaire/dropdownWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export const dropdownWidget = [
value: [''],
optionRef: {
sourceId: '#dropdownInputPropertyRef',
inherit: [{ name: '$name', id: '$id', type: 'PROPERTY' }],
inherit: [
{ id: '$id', type: 'PROPERTY', useKey: 'uuid' },
],
},
}),
floatLabel: toggle('Place label above input', {
Expand Down
6 changes: 5 additions & 1 deletion src/prefabs/questionnaire/radioWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ export const radioWidget = [
optionRef: {
sourceId: '#radioInputPropertyRef',
inherit: [
{ name: '$name', id: '$id', type: 'PROPERTY' },
{
id: '$id',
type: 'PROPERTY',
useKey: 'uuid',
},
],
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/prefabs/radioinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const beforeCreate = ({
{
id: propertyId,
type: 'PROPERTY',
name: `{{ ${model?.name}.${name} }}`,
useKey: 'uuid',
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/prefabs/selectinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ const beforeCreate = ({
{
id: propertyId,
type: 'PROPERTY',
name: `{{ ${model?.name}.${name} }}`,
useKey: 'uuid',
},
];

Expand Down

0 comments on commit 127ed4c

Please sign in to comment.