Skip to content

Commit

Permalink
fix radio button not work bug
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimdoerr committed Feb 27, 2017
1 parent 5becebd commit 98e5f93
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions assets/mblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,10 @@ function mblock_reindex(element) {
// For some browsers, `attr` is undefined; for others,
// `attr` is false. Check for both.
if (typeof attr !== typeof undefined && attr !== false) {
var value = $(this).attr('name').replace($(this).attr('name').match(/\]\[\d+\]\[/g), '][' + index + '][');
var value = attr.replace($(this).attr('name').match(/\]\[\d+\]\[/g), '][' + index + '][').replace('mblock_new_','');
$(this).attr('name', value);
}

// remove for for checkbox and radio boxes
if ($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio') {
if ($(this).parent().is('label')) {
// remove for
$(this).parent().removeAttr('for');
}
}

// checkbox problem fix
if ($(this).attr('type') == 'checkbox') {
$(this).unbind().bind('change', function () {
Expand All @@ -167,6 +159,11 @@ function mblock_reindex(element) {
});
}

// radio problem fix
if ($(this).attr('type') == 'radio' && $(this).attr('data-value')) {
$(this).val($(this).attr('data-value'));
}

// select rex button
if ($(this).prop("nodeName") == 'SELECT' && $(this).attr('id') && (
$(this).attr('id').indexOf("REX_MEDIALIST_SELECT_") >= 0 ||
Expand Down Expand Up @@ -353,10 +350,28 @@ function mblock_add_item(element, item) {
if (item.parent().hasClass(element.attr('class'))) {
// unset sortable
element.mblock_sortable("destroy");
// add element
item.after(item[0].outerHTML);

// item.after(item[0].outerHTML);
// item.after(item.clone());

var iClone = item.clone();

// fix for checkbox and radio bug
iClone.find('input:radio, input:checkbox').each(function(){
$(this).parent().removeAttr('for');
});

// fix radio bug
iClone.find('input:radio, input:checkbox').each(function(){
// fix lost checked from parent item
$(this).attr('name', 'mblock_new_' + $(this).attr('name'));
// fix lost value
$(this).attr('data-value', $(this).val());
});

// add clone
item.after(iClone);

// delete values
if (element.data().hasOwnProperty('input_delete')) {
if (element.data('input_delete') == true) {
Expand All @@ -374,6 +389,7 @@ function mblock_add_item(element, item) {
});
}
}

mblock_set_unique_id(item.next(), true);
// set count
mblock_set_count(element, item);
Expand Down

0 comments on commit 98e5f93

Please sign in to comment.