Skip to content

Commit 79df5f5

Browse files
committed
Dispatch event when the input is programmatically changed
It also calls a callback function possibly passed to the attach method. This callback is a way to update a react JSON schema form programmatically, the regular event is not catched by the form.
1 parent d1f5810 commit 79df5f5

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"dependencies": {
5959
"@jupyterlab/application": "^4.0.0",
6060
"@jupyterlab/statedb":"^4.0.0",
61+
"@lumino/algorithm": "^2.0.0",
6162
"@lumino/coreutils": "^2.1.2"
6263
},
6364
"devDependencies": {

src/connectors/local-storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The secret connector used currently should not be used in production, since the
1515
passwords are stored as plain text in the local storage of the browser'
1616
`);
1717
}
18+
1819
async fetch(id: string): Promise<ISecret | undefined> {
1920
const secrets = JSON.parse(localStorage.getItem(this.storage) ?? '{}');
2021
if (!secrets || !secrets[id]) {

src/manager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class SecretsManager implements ISecretsManager {
4242
async attach(
4343
namespace: string,
4444
id: string,
45-
input: HTMLInputElement
45+
input: HTMLInputElement,
46+
callback?: (value: string) => void
4647
): Promise<void> {
4748
const attachedId = `${namespace}:${id}`;
4849
const attachedInput = this._attachedInputs.get(attachedId);
@@ -64,6 +65,10 @@ export class SecretsManager implements ISecretsManager {
6465
// Fill the password if the input is empty and a value is fetched by the data
6566
// connector.
6667
input.value = secret.value;
68+
input.dispatchEvent(new Event('change'));
69+
if (callback) {
70+
callback(secret.value);
71+
}
6772
} else if (input.value && input.value !== secret?.value) {
6873
// Otherwise save the current input value using the data connector.
6974
this.set(attachedId, { namespace, id, value: input.value });

src/token.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export interface ISecretsManager {
1919
set(id: string, secret: ISecret): Promise<void>;
2020
remove(id: string): Promise<void>;
2121
list(namespace: string): Promise<string[]>;
22-
attach(namespace: string, id: string, input: HTMLInputElement): void;
22+
attach(
23+
namespace: string,
24+
id: string,
25+
input: HTMLInputElement,
26+
callback?: (value: string) => void
27+
): void;
2328
detach(namespace: string, id: string): void;
2429
detachAll(namespace: string): void;
2530
}

0 commit comments

Comments
 (0)