mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-28 13:31:06 +00:00
Skip validation if form submit button has formnovalidate attribute (#826)
awesome, thank you for adding a test too!
This commit is contained in:
parent
84ef04beeb
commit
f302ad6fdd
@ -2060,9 +2060,13 @@ return (function () {
|
||||
var values = {};
|
||||
var formValues = {};
|
||||
var errors = [];
|
||||
var internalData = getInternalData(elt);
|
||||
|
||||
// only validate when form is directly submitted and novalidate is not set
|
||||
// only validate when form is directly submitted and novalidate or formnovalidate are not set
|
||||
var validate = matches(elt, 'form') && elt.noValidate !== true;
|
||||
if (internalData.lastButtonClicked) {
|
||||
validate = validate && internalData.lastButtonClicked.formNoValidate !== true;
|
||||
}
|
||||
|
||||
// for a non-GET include the closest form
|
||||
if (verb !== 'get') {
|
||||
@ -2073,7 +2077,6 @@ return (function () {
|
||||
processInputValue(processed, values, errors, elt, validate);
|
||||
|
||||
// if a button or submit was clicked last, include its value
|
||||
var internalData = getInternalData(elt);
|
||||
if (internalData.lastButtonClicked) {
|
||||
var name = getRawAttribute(internalData.lastButtonClicked,"name");
|
||||
if (name) {
|
||||
|
@ -55,6 +55,21 @@ describe("Core htmx client side validation tests", function(){
|
||||
form.textContent.should.equal("Clicked!");
|
||||
});
|
||||
|
||||
it('Formnovalidate skips form validation', function()
|
||||
{
|
||||
this.server.respondWith("POST", "/test", "Clicked!");
|
||||
|
||||
var form = make('<form hx-post="/test">' +
|
||||
'No Request' +
|
||||
'<input id="i1" name="i1" required>' +
|
||||
'<button id="button" type="submit" formnovalidate></button>' +
|
||||
'</form>');
|
||||
form.textContent.should.equal("No Request");
|
||||
byId("button").click();
|
||||
this.server.respond();
|
||||
form.textContent.should.equal("Clicked!");
|
||||
});
|
||||
|
||||
it('HTML5 pattern validation error prevents request', function()
|
||||
{
|
||||
this.server.respondWith("POST", "/test", "Clicked!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user