views:

70

answers:

1

Following is an example code test harness which emulates the problem I am experiencing. Basically, when not using resizable() for the textarea, clicking on the "Content [+/-]" allows the fieldset to collapse and no textarea is shown. However, when using resizable, clicking on "Content [+/-]" causes the text area to be hidden, but the original dimensions of the textarea are retained and the the fieldset does not collapse, and the resize icon is still shown at the lower right corner.

Is there a better way to structure the HTML or am I missing an operation with jQuery/jQueryUI?

Thank you.


<!DOCTYPE html>
<html>
<head><title>SO,2</title>
<script 
  type="text/javascript" 
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;
</script>
<script 
  type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"&gt;
</script>
<link 
  rel="stylesheet" 
  type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css"/&gt;
</head>
<body>

<div id="squish1">
  <fieldset id="fs1">
    <legend id="lg1">Content [+/-]</legend>
    <textarea rows="10" cols="80" name="ta1" id="ta1"></textarea>
  </fieldset>
</div>

<script type="text/javascript">
$('#ta1').resizable();
$('#fs1').click(function(){
  $('#ta1').toggle();
});
</script>
</body>
</html>
+1  A: 

resizable() creates a wrapper around the element to be resized. If you hide the textarea, the size and display of that wrapper wouldnt change, so it still takes it's place

Use

$('.ui-wrapper',this).toggle();

instead of

 $('#ta1').toggle();

It will hide the wrapper(and of course the textarea, because of it's inside the wrapper)

If you want to toggle only when the legend receives the click, change the click()-Fuction into that:

    $('#lg1').click(function(){
    $('.ui-wrapper',this.parentNode).toggle();
});
Dr.Molle
Nice! Works like a charm. Thank you.
jtp
One note: The $('.ui-wrapper',this).toggle() solved the core issue but raised another. The toggle is triggered for every click inside the fieldset, even within the textarea itself preventing the editing of text within.
jtp
See the update in my Answer above ;)
Dr.Molle
Double awesome! The update solved both issues with this particular case. Trapping the legend click rather than the fieldset click was a much better approach. Many thanks.
jtp