kopia lustrzana https://github.com/shoelace-style/shoelace
rename variable for clarity
rodzic
f2177dccaf
commit
17ee89a5e8
|
@ -271,7 +271,7 @@ export class FormControlController implements ReactiveController {
|
|||
el.requestUpdate();
|
||||
}
|
||||
|
||||
private doAction(type: 'submit' | 'reset', invoker?: HTMLInputElement | SlButton) {
|
||||
private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | SlButton) {
|
||||
if (this.form) {
|
||||
const button = document.createElement('button');
|
||||
button.type = type;
|
||||
|
@ -283,13 +283,13 @@ export class FormControlController implements ReactiveController {
|
|||
button.style.whiteSpace = 'nowrap';
|
||||
|
||||
// Pass name, value, and form attributes through to the temporary button
|
||||
if (invoker) {
|
||||
button.name = invoker.name;
|
||||
button.value = invoker.value;
|
||||
if (submitter) {
|
||||
button.name = submitter.name;
|
||||
button.value = submitter.value;
|
||||
|
||||
['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach(attr => {
|
||||
if (invoker.hasAttribute(attr)) {
|
||||
button.setAttribute(attr, invoker.getAttribute(attr)!);
|
||||
if (submitter.hasAttribute(attr)) {
|
||||
button.setAttribute(attr, submitter.getAttribute(attr)!);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -306,15 +306,15 @@ export class FormControlController implements ReactiveController {
|
|||
}
|
||||
|
||||
/** Resets the form, restoring all the control to their default value */
|
||||
reset(invoker?: HTMLInputElement | SlButton) {
|
||||
this.doAction('reset', invoker);
|
||||
reset(submitter?: HTMLInputElement | SlButton) {
|
||||
this.doAction('reset', submitter);
|
||||
}
|
||||
|
||||
/** Submits the form, triggering validation and form data injection. */
|
||||
submit(invoker?: HTMLInputElement | SlButton) {
|
||||
submit(submitter?: HTMLInputElement | SlButton) {
|
||||
// Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
|
||||
// native submit button into the form, "click" it, then remove it to simulate a standard form submission.
|
||||
this.doAction('submit', invoker);
|
||||
this.doAction('submit', submitter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Ładowanie…
Reference in New Issue