I am using the following code:
$('#formarea')[0].reset();
This allows me to reset a form but in some cases it does not do it with the data that has been written with ajax or elements added with ajax.
I also empty the display none fields, there is some way to parameterize it so that it avoids the display none fields. also the fields with the select2 plugging are not sent to my php and before adding this line of code if I did it
Adding a class or cleaning fields by fields would mean editing a lot of code, it's a project I have and there are more than 120 different forms. the inputs follow the bootstrap design.
Current Code:
var formarea= $('#formarea *');
formarea.not("[type=radio],[type=checkbox],[type=hidden],[readonly='readonly'],[style*='display: none'],.select2-offscreen,select").each(function(){
var name = $(this).attr('name');
console.log(name);
$(this).val('');
});
I changed the code since it did not have the scope I needed, now the situation is that when using it, it eliminates the options within the Select2