Skip to content

Commit

Permalink
input type='checkbox' 対応
Browse files Browse the repository at this point in the history
配列キーの対応 (name[]=taro&name[]=jiro&name[]=saburou)
  • Loading branch information
hosokawat committed Aug 28, 2019
1 parent d854d5e commit cda70ad
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions v-ajax-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ const VAjaxForm = {
}, submit: function () {
let params = {};
for (let el of this.$el.querySelectorAll('input,select,textarea')) {
if ((typeof el.attributes['disabled'] == 'undefined')
if ((typeof el.attributes['disabled'] === 'undefined')
&& (typeof el.attributes['name'] != 'undefined')
) {
if (el.type == 'radio' && !el.checked) continue;
if ((el.type === 'radio' || el.type === 'checkbox') && !el.checked) continue;
let val = el.value;
let name = el.attributes['name'].value;
params[name] = val;
if (typeof params[name] === 'undefined') {
params[name] = val;
} else if (params[name] instanceof Array) {
params[name].push(val);
} else {
params[name] = [params[name], val];
}
}
}
this.request(params);
Expand Down

0 comments on commit cda70ad

Please sign in to comment.