Integrating jquery-ui and jquery validation - jquery-ui

I'm using jquery ui controls, and jquery validation plugin.
let's say I want to add a required class on a combobox.
The element is dynamically generated with a generic code.
Where can I add the class ?

I just need to select the next brother with the proper classes:
$('#someSelect ~ .ui-autocomplete-input').addClass('bla');

You can add this html to your view. Or take out the script tags and add this to your js file for that page. In the case below I am adding two classes to the combobox.
This combo box:
<select id="cbCars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
This is the JQuery wrapped in a html script tag:
<script type="text/javascript">
$(function () {
$("#cbCars").addClass("ui-state-active ui-corner-top");
});
</script>

Related

Placeholders in jQuery Mobile

I know there are placeholders for selects in jQuery Mobile.
<select id="salutation" data-native-menu="false">
<option id="salPlac" data-placeholder="true" value="">Salutation</option>
<option value="Mr.">Mr.</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option value="Dr.">Dr.</option>
<option value="Prof.">Prof.</option>
</select>
But are there similar placeholders for textareas and inputs when using jQuery Mobile?
Like this: (doesnt work)
<textarea type="input" class="regular" id="textBox" data-placeholder="true">Type in here</textarea>
I know they are available in HTML5, but I want to use jQuery Mobile if it's possible.
Thanks.
There is no attribute called "data-placeholder" available for text box and text area in jquery mobile. So you need to use the HTML5 placeholder attribute suggested by Omar.
Here is the link http://view.jquerymobile.com/1.3.1/dist/demos/#ui-page-top

JQuery multiselect UI how to exclude an option

I am using jQuery UI MultiSelect Widget. I want my list to have 5 options and the first one("Please Choose") to be selected by default, however I want only the last four options as to be visible and selectable from the users when the list is unfolded.Any good idea how to do that?
Thank you
You must have checked the documentation of that plugin, it has everything to customize it in all possible manner. Check out below sample code:
HTML
<select name="gender" id="gender" multiple="multiple">
<option value="MAN">MAN</option>
<option value="WOMAN">WOMAN</option>
</select>
Script
$(document).ready(function(){
$("select").multiselect({
noneSelectedText: 'Choose Options'
});
});
Fiddle

disable a jquery mobile select with knockout

is that possible to disable with knockout a jquery mobile select like this:
<select>
<option value="1">value1</option>
<option value="2">value2</option>
<option value="3">value3</option>
<option value="4">value4</option>
</select>
I tried something like this <select data-bind="attr: {disabled: 'disabled'}"> but doesnt work
You can do it with knockout.js only if select is a native one.
If it is styled with jQM then only way to disable it to use jQuery Mobile function like this:
$('select').selectmenu('disable');
or:
$('select').selectmenu('enable');

Using custom data attribute in Struts 2 s:select

I'm trying to use custom data attributes of HTML in Struts2 tags
here is my sample code
<s:select list="myList" listKey="myListVal" listValue="myListDesc" data-inputs="myListInput" ></s:select>
i was expecting something like this for example
<select >
<option value="myListVal1" data-inputs="myListInput1">myListDesc1</option>
<option value="myListVal2" data-inputs="myListInput2">myListDesc2</option>
<option value="myListVal3" data-inputs="myListInput3">myListDesc3</option>
</select>
instead I'm getting this
<select data-inputs="myListInput" >
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
Is it possible to describe data-attribute in struts select tags for Options inside it.
Override the <s:select> tag template. Or just use HTML tags with <s:iterator>
<select name="list">
<s:iterator value="myList" status="stat">
<option value="<s:property value="myListVal"/>" data-inputs="myListInput<s:property value="#stat.index"/>"><s:property value="myListDesc"/></option>
</s:iterator>
</select>
You can't inject custom attributes into a Struts2 UI Tag directly.
According to Dave Newton's comment, you can with Struts2 >= 2.1.x
But still it's not possible to apply them to the option elements instead of the select, so I'll leave the answer in case you need to extend the original select tag to define a custom behaviour (like apply certain attributes to the options).
You can extend the <s:select> Struts2 tag to allow it to manage new kind of attributes...: http://bodez.wordpress.com/2009/03/13/customising-struts2-jsp-tags/
,
or create your own tag directly, but in your case would be overkill: http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/).
Last but not least, you could even add your custom attributes once the page is rendered, using something like jQuery (demo: http://jsfiddle.net/CLNDs/ ); they will be accessible, but not visible in source.

ASP.NET MVC combo dropdown box

Is it possible to create a dropdown box in ASP.NET MVC, that has a checkbox alongside each item in the dropdown list?
I know it sounds simple, in webforms or using telerik this would be pretty simple, but I can't figure how I can implement the same thing in basic HTML.
Thanks
You can use a jQuery plugin called DropDownCheckList to get the wanted effect of a dropdownlist with multiselect options.
Its pretty easy, all you need to do is to create a html listbox and call the jQuery plugion to extend the listbox.
<script type="text/javascript">
$(document).ready(function() {
$("#listbox").dropdownchecklist();
}
</script>
<select id="listbox" multiple="multiple">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html
a dropdown with each element of the dropdown having a checkbox? that's not a standard element of HTML, why would you even need that? a multiple option is what you need:
http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html (first one)

Resources