return true;
});
- this.element.on('keyup', 'input,select,textarea', function () {
+ this.element.on('change', '.bunchmultiple', function () {
+ $this.update();
+ return true;
+ });
+
+ this.element.on('keyup', 'input' + this.bmidselector + ',select' + this.bmidselector + ',textarea' + this.bmidselector, function () {
$this.updateLegends();
return true;
});
var val = [];
var $this = this;
var id = this.element.attr('id');
- $.each(this.element.find('.item' + this.bmidselector + ':not(.sample) .subform'+ this.bmidselector), function () {
+ $.each(this.element.find('.item' + this.bmidselector + ':not(.sample) .subform' + this.bmidselector), function () {
var data = $(this).find(':input' + $this.bmidselector).serializeArray();
var filteredData = {};
$.each(data, function (k, v) {
filteredData[name] = v.value;
});
+ $(this).find('.hiddenfield').each(function () {
+ var e = $(this).attr('name').split('___');
+ var name = e.pop();
+ filteredData[name] = JSON.parse($(this).attr('value'));
+ });
+
val.push(filteredData);
});
-
- console.log(val);
this.element.find('.hiddenfield' + this.bmidselector).val(JSON.stringify(val));
},
},
initItem: function (values) {
+ var $this = this;
var collapsed = true;
var isNew = false;
if (values === undefined) {
if (collapsed) {
$(item).addClass('collapsed');
}
+ // Handle nested multiple bunch
+ $(item).find('.subform>.bunchmultiple').each(function () {
+ var newrand = $this.id + '_' + Math.round(Math.random() * 10000000);
+ var sampleId = $(this).attr('id');
+ var html = replaceAll(sampleId, newrand, $(this).html());
+ $(this).html(html);
+ $(this).attr('id', newrand)
+ });
+
$(this.element).find(".bunchmultiple__items" + this.bmidselector).append($(item));
this.setValues(item, values);
+ $(item).find('.subform>.bunchmultiple').bunchmultiple();
+
+ $(item).find('.form-group').find('input, select, .dropzone, textarea').each(function () {
+ if ($(this).closest('.bunchmultiple').attr('id') !== $this.id) {
+ return;
+ }
+ $(this).attr('data-bmid', $this.id);
+ });
- $(item).find('.form-group').find('input, select, .dropzone, textarea').attr('data-bmid', this.id);
$(document).trigger('cubist.bunchmultiple.added');
+ $(this).trigger('change');
},
setValues(item, values) {
var id = this.element.attr('id');
try {
$.each(values, function (k, v) {
- var inputs = $(item).find('[name="' + id + '___' + k + '"]');
- if (inputs.filter('[type="checkbox"]').length > 0) {
- inputs.filter('[type="checkbox"]').prop('checked', v === '1');
+ var input = $(item).find('[name="' + id + '___' + k + '"]');
+ if (input.is('.hiddenfield')) {
+ $(input).parent().attr('data-values', JSON.stringify(v));
+ } else if (input.filter('[type="checkbox"]').length > 0) {
+ input.filter('[type="checkbox"]').prop('checked', v === '1');
} else {
- inputs.val(v);
+ input.val(v);
}
});
} catch (e) {
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
+
+function replaceAll(from, to, str) {
+ var e = str.split(from);
+ return e.join(to);
+}