Skip to content

Commit af5c35e

Browse files
committed
Add new callback adjustFormValueBeforePopulating
1 parent db8c5a7 commit af5c35e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/options.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ const options: VideomailClientOptions = {
137137

138138
callbacks: {
139139
/*
140-
* a custom callback to tweak form data before posting to server
140+
* A custom callback to tweak form data before posting to server
141141
* this is for advanced use only and shouldn't be used if possible
142142
*/
143143
adjustFormDataBeforePosting: undefined,
144+
145+
/*
146+
Another custom callback to tweak a single form value before populating the form.
147+
*/
148+
adjustFormValueBeforePopulating: undefined,
144149
},
145150

146151
defaults: {

src/types/options.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PartialDeep } from "type-fest";
22

3-
import { PartialVideomail } from "./Videomail";
3+
import { PartialVideomail, Videomail } from "./Videomail";
44

55
export interface VideomailClientOptions {
66
logger: {
@@ -118,6 +118,9 @@ export interface VideomailClientOptions {
118118
adjustFormDataBeforePosting?:
119119
| undefined
120120
| ((videomail: PartialVideomail) => PartialVideomail);
121+
adjustFormValueBeforePopulating?:
122+
| undefined
123+
| ((name: string, videomail: Videomail) => string);
121124
};
122125

123126
defaults: {

src/wrappers/form.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,13 @@ class Form extends Despot {
114114
const name = formControl.getAttribute("name");
115115

116116
if (name) {
117-
const value = videomail[name];
117+
let value = videomail[name];
118118
const tagName = formControl.tagName;
119119

120+
if (this.options.callbacks.adjustFormValueBeforePopulating) {
121+
value = this.options.callbacks.adjustFormValueBeforePopulating(name, videomail);
122+
}
123+
120124
switch (tagName) {
121125
case "INPUT": {
122126
const inputControl = formControl as HTMLInputElement;

0 commit comments

Comments
 (0)