Sim! Pegunta simples não é mesmo?
Bom, ao que tudo indica, o método reset() não serve para isto, embora seja bem sugestivo!
Então, fui inventar um cadastro de pesquisa de satisfação em Ajax na empresa que trabalho, e, é claro, precisava resetar o formulário após o cadastro para sugestivamente deixar o formulário limpo novamente.
Bom, jquery é cheia de utilidades e frescuras e como eu iniciei o post falando de reset(), a ideia é que ele deveria funcionar:
// E no final me engaram?
$('form').reset()
Então, para resolver esta situação, acabei por usar a lógica das coisa fazer meu jeito:
$(':input')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
Mas, é claro, fui verificar se algum louco na face da terra já não teria inventado um plugin para resolver isto, e, como suspeitei (risos), já inventaram:
// santa criatividade!
jQuery.fn.reset = function() {
this.each(function(){
if($(this).is('form')) {
var button = jQuery(jQuery('<input type="reset" />'));
button.hide();
$(this).append(button);
button.click().remove();
} else if($(this).parent('form').size()) {
var button = jQuery(jQuery('<input type="reset" />'));
button.hide();
$(this).parent('form').append(button);
button.click().remove();
} else if($(this).find('form').size()) {
$(this).find('form').each(function(){
var button = jQuery(jQuery('<input type="reset" />'));
button.hide();
$(this).append(button);
button.click().remove();
});
}
})
return this;
};
