I am populating a select dropdown from MongoDB database and then clicking on submit to perform some action on the selected value. I want to show default text for my select dropdown but also want that the default option should not allow to click submit unless some other value is chosen.
I tried this:
<g:select name="websiteSelection"
from="${websitesList.website}" id="mySelect" noSelection="${['null':'Select Website']}"
class="styled-select" value="select" />
But this allows me to press submit when nothing is selected apart from default text. Is there any way I can achieve this requirement?
Related
I have a multiple select box in a form
<%= f.select :receipts, [], {}, multiple: true -%>
I want to ALWAYS post all options that are in the select box, but HTML only posts the ones the user has clicked on.
I could handle the submit event in JavaScript and set all the options to be selected, but I don't really want the user to see the items get selected. The form may fail to post and I'd prefer not to change anything visual on the screen.
The other thought I had was to use a hidden element and set its value to be a comma separated list of items from the multi-select box just before the submit happens. Then I don't have to mess with the selection state of the multi-select box.
Is there some Rails magic I can use instead of doing this?
I have created a profile page in php where a user using an html drop down list chooses gender. The html code is the following:
Gender<select name="gender">
<option value=" "> EMPTY </option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
After the user chooses gender the form dispatches and saves the data into database. The problem is that if the user visits again the profile page the drop down list does not keep the value that the user selected before, but shows the first option value each time. How can I modify this so that the drop down list will show the selected value that users enters before?
Set the "selected" attrubute on the correct option tag. You'll have to figure that out either on the server before you deliver the HTML or use Javascript client-side, depending on where you're storing the user's selection.
Try like below... it will help you ...
<option value=" " selected> EMPTY </option>
If we set Selected attribute in Option tag ... then it specifies that an option should be pre-selected when the page loads
after selecting and form is submited then the selected value must be saved in a session variable . and when the person visits page again set the selected attribute to the corresponding by checking the session value
I have a Rails form with a checkbox on a boolean field.
I want to replace the checkbox with a toggle button, using Twitter Bootstrap.
Is there anything baked into Rails to provide this kind of functionality? Or will I need to write a script to update the checkbox value when the toggle button is clicked?
Thanks for any pointers. After a lot of searching, I've been unable to find anything that describes this.
At this point in time, the toggle Bootstrap buttons do not have the correct markup to work out of the box with forms (source).
You can wrap around the controls to insert the correct values into your parameters map using hidden fields. If you're using AJAX requests, you can simply include them in your parameters there.
In the case of the single toggle, you could implement a function as simple as this to set the hidden value.
In your form:
<input name="toggled" value="false" />
Evaluated before submission:
function isToggled() {
$('input[name="toggled"]').value($('#toggleButton').hasClass('active'));
}
I need to write default action for the selection if user select "Please select" on dropdown menu on rails so how can I identify whether user have selected that??
The select helper generates an option tag with no specific value for the "Please select" entry. So the params hash gets assigned "Please select" for that param when you submit the form.
I'm not familiar with rails and how select boxes are handled, but in general html mark-up you could add attribute value="0" for the "Please select" element and later check for it. If the passed value is 0 you'll know that the user failed to select something from the select box.
How do you set a string to denote the required format pattern in a text box. For instance, if I have a text box displayed such as a date field, how do I display a format of "dd/mm/yyyy" to help the User complete the field. If the field is already populated when the view is displayed then the actual data should be displayed.
If the field is a drop down list, I would like to display "Please select from the list" if the field does not contain a value.
In HTML 5 you can achieve it using Placeholder attribute of input tag like this:
<input name="email" type="email" placeholder="validemail#email.com" />
However HTML5 is not yet supported by most browsers, so you will have to live with javascript based solution. Populate the desired value in textbox when page is loading (you can use CSS to make that text dim). Using javascript empty the field on "onfocus" event.
For drop down list populate "please select..." thing with Value as 0. This way you can validate on server that user has not selected any valid value.