I got a form submitted by a button type="submit",when i click it , it start the frontend validation but i also have some server validation that i have to do with ajax. For example that the name it's not used by another person.
My problem is that if i change to button type="button" the frontend validation don't execute. Only the ajax validation do it. What can i do? P/D: i use tiny.js that is similar to jquery for js events.
html
<form>
<input name="name" class="name">
<button type="submit" class="name__valid" value="save">save</button>
<form>
js
tiny.ajax("/update",
{
method: "PUT",
data: {
name: document.querySelector('name__valid').value;
},
dataType: "json",
success: function (data) {
alert('available name');
window.location = "/home?name-update=success"
},
error: function (error) {
//example: used name error
var errorJSON = JSON.parse(error.response);
console.log('Messages ' + errorJSON.messages);
}
}
);
//this validation only it's executed by de button (type submit)
var name = new ch.Validation(ch('.name__valid')[0], {
'conditions': [{
'name': 'invalid-name',
'message': 'this name it's not valid'
}]
});
event.preventDefault()maybe?