Liftweb form processing - scala

How do I test to see which option is in focus during a form submittal?
<select name="temp" id="keys">
<option selected="selected" value="ISBN">ISBN</option>
<option value="Title">Title</option>
<option value="Author">Author</option>
<option value="Publisher">Publisher</option>
<option value="Date">Date</option>
</select>
From my snippet I've tried S.param("temp")...

A common way to do this is use SHtml.select()
This way you can have the options taken from Scala code, in a typesafe manner and prone to typos.
As far as I understand, S.param("temp") should work also, if you din't mess with the <form>.

Related

AutoHotKey: How to get list of available values from drop down list?

I am trying to automate a website to get data. Usually if I know in advance what are the possible value from the drop down list, I can hard code them in my script.
But if I don't know what are the values, is there an elegant way to dynamically obtain the drop down list values?
Working sample from: https://autohotkey.com/boards/viewtopic.php?t=15574
select name="ConnectDTO.EvaluationGroupId" id="ConnectDTO_EvaluationGroupId" style="width: 260px;" required="yes" data-val-number="The field Evaluation Group must be a number." data-val="true"><option value="">Please Select</option>
<option value="4">ccpdmanagement</option>
<option value="7">AM Northern</option>
<option selected="selected" value="3">cwplanning</option>
<option value="1">mnplanning</option>
<option value="2">msplanning</option>
<option value="9">LCC</option>
<option value="6">powerquality2</option>
<option value="8">AM Southern</option>
<option value="5">tcoqueries</option>
</select>
When my script arrived on the page after loadIE(wb), is there a way to "get" the list of selection - such as ccpdmanagement, AM Northern etc...?
I know how to select them once the option is known in advance only.
pwb.document.getElementById("ConnectDTO_EvaluationGroupId").Focus()
pwb.Document.GetelementById("ConnectDTO_EvaluationGroupId").value := "1"
Thanks.
I found a solution here: https://autohotkey.com/boards/viewtopic.php?t=35467
Althought the Author stated he has a problem with the code (stated not work for some reason).
But for my purpose - to retrieve the list of all the drop down list option. It worked fine.
myDropDownList := wb.document.getElementById("your_dropdown_ID")
loop % myDropDownList.length
{
test := myDropDownList[A_Index-1].value
MsgBox %test%
}

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.

Zend_Form_Element_Select setValue is selecting more than one option

I am using Zend 1.11.10 and I am trying to set a value in a dropdown list. My code is:
$state = new Zend_Form_Element_Select("mytest");
$state->setLabel("mytest")
->setName("mytest");
$state->addMultiOption('Pear','PE');
$state->addMultiOption('Banana','BA');
$state->addMultiOption('Orange','OR');
$state->addMultiOption('Kiwi','KI');
$state->setValue('Banana');
$this->addElement($state);
The problem is that the generated HTML code is:
<select id="mytest" name="mytest" style="opacity: 0;"><option value="PE">Pear</option><option selected="selected" value="BA">Banana</option><option selected="selected" value="OR">Orange</option><option selected="selected" value="KI">Kiwi</option></select>
It is making "selected" all options after "Banana". Is this a bug in Zend?
Looks to me like you're using a non-standard FormSelect view helper. For starters, your <option> value attribute and text values are reversed and you have no label attributes.
Eg, for
$state->addMultiOption('Pear','PE');
the generated markup should be
<option value="Pear" label="PE">PE</option>
I'd also hazard a guess that there's some JavaScript playing with the DOM due to the opacity style attribute.
Using your code exactly I get:
<select name="mytest" id="mytest">
<option value="Pear" label="PE">PE</option>
<option value="Banana" label="BA" selected="selected">BA</option>
<option value="Orange" label="OR">OR</option>
<option value="Kiwi" label="KI">KI</option>
</select>
this is also with 1.11.10. Are you using custom form classes or anything else that might be affecting it?

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).

Zend_Form and Decorator help

<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.