Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with moving Custom TVs to tab #8

Open
kulmjens opened this issue Nov 28, 2012 · 1 comment
Open

Problem with moving Custom TVs to tab #8

kulmjens opened this issue Nov 28, 2012 · 1 comment

Comments

@kulmjens
Copy link

I came across a problem in ManagerManager 0.3.9 in MODX Evolution 1.0.7. I wanted to use the function mm_moveFieldsToTab to move some TVs to another tab. Some of them are custom TVs and contain select-fields and they weren't moved. :-(

In mm.inc.php there is a function filling the variable $mm_fields. It goes through the TVs an assigns the name and type. Unfortunately there is no case for custom TVs and the default type "input" is used. So it only works for custom TVs with an input textfield.

I added the following to the switch on line 131:

case 'custom_tv':
    $t = 'custom_tv';
break;

Then in fields_inc.php I had to change the default case of the switch in the function mm_moveFieldsToTab on line 268 from

// What type is this field?
if (isset($mm_fields[$field])) {
    $fieldtype = $mm_fields[$field]['fieldtype'];
    $fieldname = $mm_fields[$field]['fieldname'];
    $output .= '
    var toMove = $j("'.$fieldtype.'[name='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move
    toMove.next("tr").find("td[colspan=2]").parents("tr").remove(); // Get rid of line after, if there is one
    var movedTV = toMove.appendTo("#tab'.$newtab.'>table:first"); // Move the table row
    movedTV.after(ruleHtml); // Insert a rule after 
    movedTV.find("td[width]").attr("width","");  // Remove widths from label column
    $j("[name^='.$fieldname.']:first").parents("td").removeAttr( "style" );  // This prevents an IE6/7 bug where the moved field would not be visible until you switched tabs
    ';
}

to

// What type is this field?
if (isset($mm_fields[$field])) {
    $fieldtype = $mm_fields[$field]['fieldtype'];
    $fieldname = $mm_fields[$field]['fieldname'];
    if($fieldtype == 'custom_tv') {
        $output .= 'var toMove = $j("*[name^='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move';
    } else {
        $output .= 'var toMove = $j("'.$fieldtype.'[name='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move';
    }
    $output .= '
    toMove.next("tr").find("td[colspan=2]").parents("tr").remove(); // Get rid of line after, if there is one
    var movedTV = toMove.appendTo("#tab'.$newtab.'>table:first"); // Move the table row
    movedTV.after(ruleHtml); // Insert a rule after 
    movedTV.find("td[width]").attr("width","");  // Remove widths from label column
    $j("[name^='.$fieldname.']:first").parents("td").removeAttr( "style" );  // This prevents an IE6/7 bug where the moved field would not be visible until you switched tabs
    ';
}

Because one doesn't know what kind of input-field a custom TV has, could also be a select or textarea, I used the * to match any element with a name starting with $fieldname. And using [name^= is because selects, checkboxed and radios have a fieldname suffixed with [].

This workaround works for me. Hopefully it will be integrated in the next version of ManagerManager.

@kulmjens
Copy link
Author

Oh, I just realized that you can leave out the * before the [name^='.$fieldname.'] statement. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant