Show/Hide Dependant Fields - Uploads Fix?

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 29, 2012   (RSS)

By Perchpole - May 27, 2012

Hello, All -

I wondered if anyone knew of a workaround for the bug/feature which results in upload fields being rendered very tall?!!

It's a very annoying quirk of an otherwise extremely useful little plugin.

:0/

Perch

Re: [Perchpole] Show/Hide Dependant Fields - Uploads Fix?

By Jason - May 29, 2012

Hi Perch,

I haven't encountered this particular issue before, could you provide some extra information?

Does this happen to any upload field in a section using the show/hide plugin, or only upload fields that are being shown/hidden?

Thanks,
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Perchpole] Show/Hide Dependant Fields - Uploads Fix?

By Perchpole - May 29, 2012

Hi, Jason -

I've just had a look at the underlying code of the that appears in the editor window. Under normal circumstances an upload field would look like this:

<iframe width="100%" height="89" frameborder="0" class="uploadIframe" src="?menu=record&amp;action=uploadList&amp;fieldName=picture&amp;num=&amp;preSaveTempId=x4fc5155facc47" id="picture_iframe"></iframe>

However, when using the plugin - and after "revealing" the field - it looks like this:

<iframe width="100%" height="800" frameborder="0" class="uploadIframe" src="?menu=record&amp;action=uploadList&amp;fieldName=galleryImage&amp;num=&amp;preSaveTempId=x4fc5155facc47" id="galleryImage_iframe"></iframe>

Some how it now has a height of 800px. No wonder it's so tall!

:0)

Perch

Re: [Perchpole] Show/Hide Dependant Fields - Uploads Fix?

By Jason - May 29, 2012

Hi Perch,

This one took some searching. This is a bug that presents when a upload field is hidden when the page loads and is then shown. What we need to do is to add in a function call that automatically resizes the upload field to an appropriate size. In the plugin, you need to make this change:

<script>
var showHideDependantFields_showRules = <?php echo json_encode($showRules); ?>;
var showHideDependantFields_hideRules = <?php echo json_encode($hideRules); ?>;
$(function(){
for (var fieldName in showHideDependantFields_showRules) {
$('SELECT[name="' + fieldName + '"]').change(showHideDependantFields_update);
}
showHideDependantFields_update();
});
function showHideDependantFields_update() {
// hide all

for (i in showHideDependantFields_hideRules) {
$('*[name="' + showHideDependantFields_hideRules + '"]').closest('TR').hide();
$('*[name^="' + showHideDependantFields_hideRules + ':"]').closest('TR').hide();
$('#' + showHideDependantFields_hideRules + '_iframe').closest('TR').hide();


}
// for each list field, show requested fields
for (var listFieldName in showHideDependantFields_showRules) {
var value = $('SELECT[name="' + listFieldName + '"] OPTION:selected').val();
var fieldsToShow = showHideDependantFields_showRules[listFieldName][value];
if (!fieldsToShow) { fieldsToShow = showHideDependantFields_showRules[listFieldName]['_any_value_']; }

if (fieldsToShow) {
for (i in fieldsToShow) {
$('*[name="' + fieldsToShow + '"]').closest('TR').show();
$('*[name^="' + fieldsToShow + ':"]').closest('TR').show();
$('#' + fieldsToShow + '_iframe').closest('TR').show();

//resize element if iframe is being shown
var closestTR = $('#' + fieldsToShow + '_iframe').closest('TR');
if (closestTR.css('display') == "table-row") {
resizeIframe(fieldsToShow + '_iframe');
}

}
}
}
}
</script>


That should take care of the issue.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/