Jump to content

Recommended Posts

Hi,

 

I have a form which I show / hide fields based on a users selection.  I use JQuery for this:

<script type="text/javascript">
function toggle_field_type() {
	var field_type = $('#link option:selected').text();
	if (field_type == '') {
		$('#url').parent().hide();
		$('#pdf').parent().hide();
		/*$('#url-label').parent().hide();
		$('#pdf-label').parent().hide();*/
	}
	if (field_type == 'PDF') {
		$('#url').parent().hide();
		$('#pdf').parent().show();
	} else if (field_type == 'Url') {
		$('#url').parent().show();
		$('#pdf').parent().hide();
	}
}

$(document).ready(function(){
	toggle_field_type();    
	$('#link').change(function() {
		toggle_field_type();
	});
})
</script>

 

This is working fine, however, I need to also hide the labels for these two fields.  Does anyone know how to do this?

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/181005-zf-hiding-zend_form-labels/
Share on other sites

Here is the HTML generated:

 

<dt id="link-label"><label for="link" class="optional">Link:</label></dt>
<dd id="link-element">
<select name="link" id="link">
    <option value="" label=""></option>
    <option value="Url" label="Url">Url</option>
    <option value="PDF" label="PDF">PDF</option>
</select></dd>

<dt id="url-label"><label for="url" class="optional">Url:</label></dt>
<dd style="display: block;" id="url-element">
<input name="url" id="url" value="" type="text"></dd>
<dt id="pdf-label"><label for="pdf" class="optional">PDF:</label></dt>
<dd style="display: none;">
<input name="MAX_FILE_SIZE" value="133169152" id="MAX_FILE_SIZE" type="hidden">
<input name="pdf" id="pdf" type="file"></dd>

 

and here is the zend_form:

 

	$elements['link'] = $this->createElement( 'select', 'link' )
		->setLabel('Link:')
		->setMultiOptions(array('' => '', 'Url'=>'Url', 'PDF'=>'PDF'));

	$elements['url'] = $this->createElement( 'text', 'url' )->setLabel('Url:');	
	$elements['pdf'] = $this->createElement( 'file', 'pdf' )->setLabel('PDF:');

	$elements['date'] = $this->createElement( 'text', 'date' )->setLabel('Date:');

 

we'd need to see the HTML code the script applies to...

 

I hide the elements named "pdf" and "url".  I just need to also hide their labels.  I tried hiding by the label name "pdf-label" and "url-label" but this just hid the whole form.

Does anybody have any idea on this?

 

Thank you.

 

Here is the HTML generated:

 

<dt id="link-label"><label for="link" class="optional">Link:</label></dt>
<dd id="link-element">
<select name="link" id="link">
    <option value="" label=""></option>
    <option value="Url" label="Url">Url</option>
    <option value="PDF" label="PDF">PDF</option>
</select></dd>

<dt id="url-label"><label for="url" class="optional">Url:</label></dt>
<dd style="display: block;" id="url-element">
<input name="url" id="url" value="" type="text"></dd>
<dt id="pdf-label"><label for="pdf" class="optional">PDF:</label></dt>
<dd style="display: none;">
<input name="MAX_FILE_SIZE" value="133169152" id="MAX_FILE_SIZE" type="hidden">
<input name="pdf" id="pdf" type="file"></dd>

 

and here is the zend_form:

 

	$elements['link'] = $this->createElement( 'select', 'link' )
		->setLabel('Link:')
		->setMultiOptions(array('' => '', 'Url'=>'Url', 'PDF'=>'PDF'));

	$elements['url'] = $this->createElement( 'text', 'url' )->setLabel('Url:');	
	$elements['pdf'] = $this->createElement( 'file', 'pdf' )->setLabel('PDF:');

	$elements['date'] = $this->createElement( 'text', 'date' )->setLabel('Date:');

 

we'd need to see the HTML code the script applies to...

 

I hide the elements named "pdf" and "url".  I just need to also hide their labels.  I tried hiding by the label name "pdf-label" and "url-label" but this just hid the whole form.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.