How to convert multi select form field with GET tto have propper URL? - url

<select name="channel[]" multiple="multiple">
<option value="pants">Pants</option>
<option value="tshirts">T-Shirts</option>
<option value="sweats">Sweats</option>
</select>
So, form is GET, and if I select multiple, and when I click on submit URL is like:
?channel[]=pants&channel[]=tshirts
I need it to be like:
?channel=pants+tshirts

This cannot be achieved with an HTML only form. You'll have to incorporate javascript to manipulate the value of channel.

Related

Get the selected option's text field in controller in Ruby

I know how to get the value of the selected option in the dropdown in controller. Using
params[:category_id]
My question is for a select like this
<select name="category_id">
<option value="0">New</option>
<option value="1">SubCategory1</option>
<option value="2">SubCategory2</option>
<option value="3">SubCategory3</option>
</select>
How can i also get the selected text after request is posted to controller? So if user selects Option 1, I want "0" as well as "New".
#shaurya, Not sure why you want the text value from the form post. Can you look up the value in config['Categories'] using category_id?

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

Ruby RoR, Ransack, multiple select query fails

using the ransack gem i've seen that it should be possible to use a form with multiple select.
using the basic html for the select form I use, and then select BOTH options to that I can attempt to search for either value
<select id="q_c_0_v_0_value" name="q[c][0][v][0][value][]" size="1" multiple="multiple">
<option value="SGD">SGD</option>
<option value="USD">USD</option>
</select>
and also tried
<select id="q_c_0_v_0_value" name="q[c][0][v][0][value]" size="1" multiple="multiple">
<option value="SGD">SGD</option>
<option value="USD">USD</option>
</select>
with combinations for all of the predicates "equal any", "contains any" etc,
I get resulting
SELECT "auctions".* FROM "my_table" WHERE (("auctions"."currency" LIKE '%["SGD", "USD"]%'))
and
SELECT "auctions".* FROM "my_table" WHERE ("auctions"."currency" LIKE '%USD')
Any ideas, the link https://github.com/ernie/ransack/issues/7 says its possible, but I dont seem to get the right results.

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.

Read only drop down

Is there a good way to make an HTML dropdown read only. Using disabled attribute of select seems to work, but the value is not posted.
<select disabled="disabled">
I have a complex page with lots of javascript and ajax. Some actions in the form cause to drop down to be read only some actions let user decide the value.
Edit: Is there a better way other than using a hidden input?
If you do not want user to pick an option, how is this different from read-only input type="text"?
<select name="selectbox" disabled="disabled">
<option>option 1</option>
<option selected="selected">option 2</option>
<option>option 3</option>
</select>
Correct me if I am wrong, but if an option is selected, the value is sent

Resources