Skip to content

Commit 411553b

Browse files
authored
fix: Set form value on manual value update (#914)
* fix: Set form value on manual value update * Remove extra logic from gcds-select
1 parent 872e699 commit 411553b

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

packages/web/src/components/gcds-date-input/gcds-date-input.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ export class GcdsDateInput {
9191
validateValue() {
9292
if (this.value && !isValidDate(this.value)) {
9393
this.errors.push('value');
94-
this.value = '';
94+
this.value = null;
9595
console.error(
9696
`${i18n['en'].valueError}${i18n['en'][`valueFormat${this.format}`]} | ${i18n['fr'].valueError}${i18n['fr'][`valueFormat${this.format}`]}`,
9797
);
9898
} else if (this.errors.includes('value')) {
9999
this.errors.splice(this.errors.indexOf('value'), 1);
100100
}
101+
102+
if (this.value) {
103+
this.splitFormValue();
104+
this.internals.setFormValue(this.value);
105+
}
101106
}
102107

103108
/**

packages/web/src/components/gcds-input/gcds-input.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export class GcdsInput {
129129
*/
130130
@Prop({ mutable: true }) value?: string;
131131

132+
@Watch('value')
133+
watchValue(val) {
134+
this.internals.setFormValue(val ? val : null);
135+
}
136+
132137
/**
133138
* String to have autocomplete enabled.
134139
*/

packages/web/src/components/gcds-select/gcds-select.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export class GcdsSelect {
9090
*/
9191
@Prop({ mutable: true }) value?: string;
9292

93+
@Watch('value')
94+
watchValue(val) {
95+
this.internals.setFormValue(val ? val : null);
96+
}
97+
9398
/**
9499
* Error message for an invalid select element.
95100
*/
@@ -262,6 +267,7 @@ export class GcdsSelect {
262267

263268
if (option.hasAttribute('selected')) {
264269
this.value = value;
270+
this.internals.setFormValue(value);
265271
this.initialValue = this.value ? this.value : null;
266272
}
267273
}

packages/web/src/components/gcds-textarea/gcds-textarea.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class GcdsTextarea {
131131
@Watch('value')
132132
watchValue(val) {
133133
this.shadowElement.value = val;
134+
this.internals.setFormValue(val ? val : null);
134135
}
135136

136137
/**

0 commit comments

Comments
 (0)