File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,25 @@ const clientScript = Astro.locals.forms.scriptToRun;
35
35
<script >
36
36
declare global {
37
37
interface Window {
38
- __CSEvent: (event: KeyboardEvent, id: string) => void;
38
+ __enterToSubmit: (event: KeyboardEvent, id: string) => void;
39
+ submitForm(value: HTMLElement | string): void;
39
40
}
40
41
}
41
42
42
- window.__CSEvent = function(event, id ) {
43
+ window.__enterToSubmit = function (event) {
43
44
if (event.code === 'Enter') {
44
45
event.preventDefault();
45
- document.getElementById(id )?.click();
46
+ document.getElementById((event.target as HTMLElement).getAttribute('data-submit')! )?.click();
46
47
}
47
- }
48
+ };
49
+
50
+ window.submitForm = function (value: any) {
51
+ if (typeof value !== 'string') {
52
+ value = value.getAttribute('data-submit');
53
+ }
54
+ if(value == null){
55
+ return console.warn('submitForm: value is null, make sure you pass `this` to this method or an id of the button you want to submit.');
56
+ }
57
+ document.getElementById(value)?.click();
58
+ };
48
59
</script >
Original file line number Diff line number Diff line change 1
1
export function addOnSubmitClickEvent ( buttonId ?: string | false , allProps ?: { [ key : string ] : string } ) {
2
2
if ( buttonId ) {
3
- allProps . onkeypress = `__CSEvent(event, '${ buttonId } ');${ allProps . onkeypress ?? '' } ` ;
3
+ allProps [ "data-submit" ] = buttonId ;
4
+ allProps . onkeypress = `__enterToSubmit(event)${ allProps . onkeypress ? ';' + allProps . onkeypress : '' } ` ;
4
5
}
5
6
}
You can’t perform that action at this time.
0 commit comments