grails g:select tag - grails

I am using a g:select tag like this:
<td><g:select name="newCity"
id="${'newCity_' +cityData.uid}"
from="${cityData.name}"
value="${cityData.someValue}"
noSelection="${['null':'Select City...']}" class="newCity" />
</td>
which renders the following HTML:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" >A</option>
<option value="B" >B</option>
<option value="C" >C-</option>
<option value="D" >D</option>
</select>
</td>
However, I want my HTML to look like this; with class inserted since I am doing some javascript validation:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" class="populated" >A</option>
<option value="B" class="notpopulated" >B</option>
<option value="C" class="populated" >C</option>
<option value="D" class="notpopulated" >D</option>
</select>
</td>
Is this possible?
Do I need to create a custom tag library to acheive this?
Any help will be appreciated, Thanks!

I don't believe this is possible. The select tag implementation (which writes out the <option> tags) calls the private method writeValueAndCheckIfSelected to fill in the option, and this is not aware of any class names.
There is a 2 year old New Feature Request on the Grails JIRA, but I think you may be stuck rolling your own tag to do this for your specific situation.

Related

show "select option" as default value in JQuery UI select

I am using the JQuery UI to be able to show images within a select box:
see
http://jqueryui.com/selectmenu/#custom_render
But how using this can I make "Select an option" the default value that appears within the selectbox but also does not show when the select drops down?
Thanks!
HTML code is as follows
<fieldset>
<select name="filesA" id="country">
<option data-class="austria" /> Austria</option>
<option data-class="belgium"/> Belgium</option>
<option data-class="bulgaria" />Bulgaria</option>
...
</select>
</fieldset>
include "Select an option" as one of the option and disable the option, So the user can't select it. Here is the code
<fieldset>
<select name="filesA" id="country">
<option selected="selected" disabled="true" /> Select an Option</option>
<option data-class="austria" /> Austria</option>
<option data-class="belgium"/> Belgium</option>
<option data-class="bulgaria" />Bulgaria</option>
</select>
</fieldset>

Getting selected item from ASP MVC3 drop down list

I am trying, without any luck, to use the selected item from a drop down list in the controller. I've stepped through the code and can see that each of the string values are "null" after they should be assigned.
Below is the code from the View
<span id="searchBox" class="boxMe" >
<select id="Table" title="Table" style="font-size:8pt;">
<option value="default">--Table Name--</option>
<option value="CE">CE</option>
<option value="PT">PT</option>
</select>
<select id="IssueType" style="font-size:8pt;">
<option value="default">--Issue Type--</option>
<option value="W">Warning</option>
<option value="E">Error</option>
</select>
<select id="Status" style="font-size:8pt;">
<option value="default">--Status Type--</option>
<option value="O">Open</option>
<option value="U">Under Review</option>
</select>
<input type="image" src="#Url.Content("~/Content/Images/Filter.bmp")" alt="Filter" style="padding-top: 0px;" />
</span>
And here is what I have in the controller. As this is a search filter I have this in the Index() method at the moment.
public ViewResult Index(FormCollection dropDownSelection)
{
string table = dropDownSelection["Table"];
string issue = dropDownSelection["IssueType"];
string status = dropDownSelection["Status"];
return View(db.FollowUpItems.ToList());
}
You should use the name attribute on your <select> tags, rather than id. The name is what is used as the key in the form post:
<select name="Table" title="Table" style="font-size:8pt;">
If you haven't already, you should also wrap your inputs in <form> tags:
<span ...>
<form method="post">
<!-- Inputs -->
</form>
</span>

How to validate radio buttons, selects, and checkboxes on iPad

JSFiddle demonstrating the problem... http://jsfiddle.net/9Lzj6/2/
I am using the jQuery Validation Plugin http://docs.jquery.com/Plugins/Validation && https://github.com/jzaefferer/jquery-validation to validate a form.
JS
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
$("#patient_info_form").validate({
rules: {
"data[gender]": {required :true},
"data[dob_month]": "required",
"data[dob_day]": "required",
"data[dob_year]": "required"
}
});
</script>
HTML
<form id="patient_info_form" name="patient_info_form" action="..." method="post">
<select name="data[dob_month]" id="data[dob_month]" required="required">
<option value="" selected="selected"></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
</select>
<select name="data[dob_day]" id="data[dob_day]" required="required">
<option value="" selected="selected"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="data[dob_year]" id="data[dob_year]" required="required">
<option value="" selected="selected"></option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
</select>
<label for="gender_male" class="button_gender male">
<input type="radio" name="data[gender]" value="male" id="gender_male" required="required">
</label>
<label for="gender_female" class="button_gender female">
<input type="radio" name="data[gender]" value="female" id="gender_female" required="required">
</label>
</form>
iPad PROBLEM
It works perfectly in a standard browser (tested in Chrome), but it doesn't work at all on an iPad. I am 100% new to programming for an iPad and (unfortunately for me) this site will only be accessed via iPad.
Is there something more I need to do with the jQuery Validation Plugin to get it to work on an iPad? I also tried jQuery Mobile without luck, but I'm willing to give it (or anything else) another shot with guidance.
Can someone please provide links to a tutorial, plugin, or example code that will show me how to validate selects, radio groups (no default, but one selection required), and checkboxes (no default, but one selection from a list required - not shown in the example code above but I will need that too)?
P.S. I don't need a popup or error message. I simply need to stop the form submission if all the requirements are not met.
Thanks in advance for the help.

Help with rails collection select

I need to add different values for each option tag in my collection_select cause Im trying to use this jquery plugin.... How do I do that?
Heres my collection select code
<%= e.collection_select(:id,State.all,:id,:name) %>
The output should be something like
<select name="state[id]" id="state_id" class="selectable">
<option value="">-- select --</option>
<option value="1" title="florida">Florida</option>
<option value="2" title="georgia">Georgia</option>
</select>
Please help.
Hmm, I believe you gotta write your own helper to do so.

Help with asp.net mvc and Select List Dropdown

I want to build this dropdowns with these specific attributes.. How can I do this? Im using LinqToSql. Each Company has employees
<select name="companies" id="companies" class="selectable">
<option value="">-- select --</option>
<option value="1" title="company1">Company1</option>
<option value="2" title="company2">company2</option>
<option value="3" title="company3">company3</option>
<option value="4" title="company4">company4</option>
</select>
<select name="employees" id="employees" class="selectable">
<option value="">-- select --</option>
<option value="1" class="company1">John</option>
<option value="2" class="company1">michale</option>
<option value="4" class="company2">brian</option>
<option value="5" class="company2">mark</option>
<option value="6" class="company3">daniel</option>
<option value="7" class="company3">rose</option>
</select>
Do I have to build my own helper? please help.
this all comes from Database and I have Company and Employee with LINQTOSQL classes
As far as I know yes... The default html helper doesn't give you the ability to set the title or the class attribute on the options...
I would recommend building your own (or looking around to see if someone else has done one that solves this problem).
If you do build your own I would use lambda's (anonymous linq delegates) to capture/define the attributes your are after for the options. That way you can reuse it over and over. Let me know if you need help with this.
In asp.net MVC you already have a lot of built in Helpers. For the dropdown I would do something like this :
<%= Html.DropDownList("<name>", "<selectlist collection>", new { #class = "<css class>", title = "<title>" }) %>

Resources