Zend_Form and Decorator help - zend-framework

<select name="day" id="day">
<option value="0" label="Day:">Day:</option>
<option value="1" label="1">1</option>
</select>
<select name="month" id="month">
<option value="0" label="Month:">Month:</option>
<option value="1" label="January">January</option>
</select>
<select name="year" id="year">
<option value="2010" label="2010">2010</option>
</select>
Can I build a form part like this format using Zend_Form and Decorator? I have read many posting but couldn't find any which helps to pack more than one elements together inside a "dd" tag. Does it possible or not?

http://weierophinney.net/matthew/archives/217-Creating-composite-elements.html
This post goes onto explain how to create a composite object using Zend_Form_element and settings up custom decorators.
It is also built around having all date fields grouped together so you could probably just modify this example to get what you want.

Related

Simple Form Not Submitting Post Values

I saw two other questions here with similar problems but neither answered the question that helps make this one work and the form itself is so basic that I can't imagine why it's not working. As you can see, it is a simple self-submitting select box. One of the other questions indicated that having name= and the label having a matching for= was the answer but this has those things already so no help there.
In fact, this form is generated dynamically (this is one of the simplest versions of it) and has been online and working for years so I am mystified about why it suddenly posts nothing! It causes the form to reload when a different selection is made but does not provide the ID value or any other post values. Anyone see something I missed or did the basics of forms somehow change?
<form id="Search" method="post" name="search" action="/admin/adminform.php">
<fieldset>
<legend>Select Entry</legend>
<p><label for="ID">Select</label>
<select name="ID" id="ID" onchange="this.form.submit()">
<option value=""></option>
<option value="4">Entry 4</option>
<option value="2">Entry 2</option>
<option value="1">Entry 1</option>
<option value="8">Entry 8</option>
<option value="6">Entry 6</option>
<option value="9">Entry 9</option>
<option value="5">Entry 5</option>
<option value="3">Entry 3</option>
</select>
<noscript>
<input type="submit" value="Get Selected Entry" name="Search">
</noscript>
</fieldset>
</form>
I looked at this all day without any success but then as soon as I posted the question as a last resort, I found the problem which was nothing to do with the form. There was another function being called that tests for whether or not JavaScript is enabled which does so by submitting a post that was apparently overpowering this one. Simply putting a conditional around it so that it runs only once fixed the form in question! For reference, here is the function causing the problem and the outer-most conditional sorted it out.
function IsJavaScript() {
if (!isset($_SESSION['JSEnabled'])) :
if (isset($_POST['jstest'])) :
return TRUE;
else :
echo '<form name="jsform" id="jsform" method="post" style="display:none">';
echo '<input name="jstest" type="text" value="true" />';
echo '<script language="javascript">';
echo 'document.jsform.submit();';
echo '</script>';
echo '</form>';
return FALSE;
endif;
endif;
}

Grails, editable value in <g:select>

I want to give the users an opportunity to type in their own text if not in the list. This text should not be added to the list but it should be the value sent when the form is submitted.
I have the feeling that this is not possible with the but what other solutions exist? This is common in windows applications at least.
Take a look at datalist
gsp:
<label>Choose an colour:
<input list="colours" name="aColour" /></label>
<datalist id="colours">
<option value="Red">
<option value="Blue">
<option value="White">
</datalist>
controller:
params.aColour

How to set custom data attbributes with zend form select?

I am using Zend_Form_Element_Select to create a select form element. Here's how the inner HTML is rendered:
<option value="9" label="Biscuits">Biscuits</option>
<option value="10" label="Scones">Scones</option>
<option value="11" label="Cakes">Cakes</option>
Now, I want to be able to include a custom data attribute, data-qty, with each option, per the following example:
<option value="9" label="Biscuits" data-qty="27">Biscuits</option>
<option value="10" label="Scones" data-qty="12">Scones</option>
<option value="11" label="Cakes" data-qty="21">Cakes</option>
I can't see any way to do this out of the box so I think I'll need to extend the select element, create a new decorator, or some such solution. Any ideas?

jQuery select tag IE8 issue

I have two selects that initially render this way in both firefox and IE8:
<select id="cntctMap_PRSNL_TITL_TXT" >
<option value="Dr.">Dr.</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option selected="" value="Mr.">Mr.</option>
</select>
<select id="cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA"">
<option value="01">Focus</option>
<option value="02">Prospect</option>
<option value="03">Center Of Influence</option>
</select>
So far so good as only the first select has a value returned from the server-side, the second does not.
On document load I pull the html for the second select, i.e. $("#cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA").html());
In IE the returned string is:
<option selected value="01">Focus</option><option value="02">Prospect</option><option value="03">Center Of Influence</option>
Notice the 'selected' attribute
But in firefox it's:
<option value="01">Focus</option><option value="02">Prospect</option><option value="03">Center Of Influence</option>
The reason this is important to me is that I want to prepend an option, i.e.
$("#cntctMapCUST_SEGM_US_RETAIL_SALES_SMA").prepend(selectOption);
And have the prepended option value show in the dropdown box, but I only want to do this for those selects that don't have a server-side value.
In IE, I can't tell which is which since 'selected' comes back in all cases. This is also true if I use $("#cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA option:selected")); In IE, it always returns a 'selected' option.
Anyone know a way around this?
As discussed in the comments, I suggest adding a special class (e.g. has-default) to selects that have server-side values. This is done on the server-side when you render the tags.
<select id="cntctMap_PRSNL_TITL_TXT" class="has-default">
<option value="Dr.">Dr.</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option selected="" value="Mr.">Mr.</option>
</select>
<select id="cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA">
<option value="01">Focus</option>
<option value="02">Prospect</option>
<option value="03">Center Of Influence</option>
</select>
...
Using jQuery, you can target selects with server-side values:
$('select.has-default').prepend(selectOption);
The above statement will only prepend selectOption to selects that have the has-default class. This is more consistent because it doesn't rely on whether browsers mingle with the <option> tags.

Select the first element of a list with prototype

I have a form with 3 lists like this and I need every time one of the lists change put the others in cero 0, I need this in prototype or pure Javascript
<select id="1" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="2" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="3" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
thanks.
Here's a working demo using Prototype
Basically, it finds all select elements with the class resetOthers, and listens for the onchange event (don't use the onchange HTML attribute - it's cleaner to add the JavaScript behavior via JavaScript once the page has loaded).
When a select changes, it loops through the select elements, and sets each to the value of the first option (except for the one that triggered the event, of course).