Reputation: 27
I want to exclude selects with empty values from serialization.
I'm trying to achieve this like so:
var form = $('#myForm');
var str = $(':not(select[value=""])', form).serialize();
No erros, and the result is the entire form. The not() method gives the same.
What is possibly wrong?
EDIT: The question which was listed as possible duplicate to mine asks about possible implemntations for exlcuding empty fields frm serialization, while mine states that not() Selector
doesn't work, asks why and for different to above mentioned solution.
Upvotes: 1
Views: 131
Reputation: 115222
Which filters element with element attribute value
which equals to an empty string and not the element with current value as an empty string.
filter()
method.
var str = $(':input', form).filter(function(){
return this.value.trim() != '';
}).serialize();
select
tags then do it like.
var str = $(':input', form).filter(function(){
return !($(this).is('select') && this.value.trim() == '');
}).serialize();
Upvotes: 3