зеркало из https://github.com/dotnet/aspnetcore.git
fix "Blazor enhanced form handling doesn't honor button formmethod attribute" (#51942)
This commit is contained in:
Родитель
1ab87c9427
Коммит
36ffda05bd
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -132,6 +132,10 @@ function onDocumentSubmit(event: SubmitEvent) {
|
|||
// Replicate the normal behavior of overriding action attribute of form element
|
||||
url = new URL(submitter.formAction);
|
||||
}
|
||||
if (submitter.formMethod) {
|
||||
// Replicate the normal behavior of overriding method attribute of form element
|
||||
fetchOptions.method = submitter.formMethod;
|
||||
}
|
||||
}
|
||||
|
||||
if (fetchOptions.method === 'get') { // method is always returned as lowercase
|
||||
|
|
|
@ -1368,6 +1368,17 @@ public class FormWithParentBindingContextTest : ServerTestBase<BasicTestAppServe
|
|||
Browser.Equal("Formaction url", () => Browser.Exists(By.TagName("html")).Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SubmitButtonFormmethodAttributeOverridesEnhancedFormMethod()
|
||||
{
|
||||
GoTo("forms/form-submit-button-with-formmethod");
|
||||
Browser.DoesNotExist(By.Id("submitted"));
|
||||
|
||||
Browser.Exists(By.Id("submit-button")).Click();
|
||||
|
||||
Browser.Equal("Form submitted!", () => Browser.Exists(By.Id("submitted")).Text);
|
||||
}
|
||||
|
||||
// Can't just use GetAttribute or GetDomAttribute because they both auto-resolve it
|
||||
// to an absolute URL. We want to be able to assert about the attribute's literal value.
|
||||
private string ReadFormActionAttribute(IWebElement form)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
@page "/forms/form-submit-button-with-formmethod"
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
|
||||
<h1>Form Submit Button with formaction</h1>
|
||||
|
||||
<form data-enhance method="get" @onsubmit="() => _submitted = true" @formname="someform">
|
||||
<AntiforgeryToken />
|
||||
<input id="submit-button" type="submit" formmethod="post" />
|
||||
</form>
|
||||
|
||||
@if (_submitted)
|
||||
{
|
||||
<p id="submitted">Form submitted!</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
bool _submitted = false;
|
||||
}
|
Загрузка…
Ссылка в новой задаче