views:

28

answers:

2

Hi, i am using Zend Frameworks ViewHelpers. I am trying to pass something to set disabled attribute in SELECT. for example if $countries = array(1=>'Select Option', 2=>'us', 3=>'uk')

and formSelect('country','us',null,$this->countries)

I need to diable first option i.e. 'Select Option'

Do you have any idea ?

Thanks in addvance

+1  A: 

I don't think you can disable one element? If you disable it then why have it at all?

You can only disable the whole <select> input.

Suggest you write validation to not accept the first element.

Edit after OP's comment about being able to do this

Here is another answer

// Get the countries element (do this after adding your options), then set the 
// attribute disable for option '1'
$form->getElement("countries")->setAttrib("disable", array(1));

This is suggested here

jakenoble
actually i need to display it(just to ask user that Select Following option) but it not be selectable
Gugu
You need validation then, at least at the server side. I am pretty sure you cannot disable individual `<option>` elements within a `<select>` element. Try it using basic HTML then you'll know.
jakenoble
Try this <select> <option disabled = "disabled">--SELECT OPTION--</option> <option selected = "selected" value = "us">US</option> <option value = "uk">UK</option></select>
Gugu
i hope you can see, you can do it in normal HTML
Gugu
@jakenoble sorry, its not working
Gugu
@Gugu, new answer posted as an edit
jakenoble
A: 

Credit goes to jakenoble.
Just reformatted the code to use the formSelect-viewhelper instead of a form-element.

<?php
$countries = array(1 => 'Select Option', 2 => 'us', 3 =>'uk');
echo $this->formSelect('country', 2, array('disable' => array(1)), $countries)

This will result in:

<select name="country" id="country"> 
    <option value="1" label="Select Option" disabled="disabled">Select Option</option> 
    <option value="2" label="us" selected="selected">us</option> 
    <option value="3" label="uk">uk</option> 
</select>
Benjamin Cremer