I am trying to figure out how to deal with two select boxes with the same options (I am using formtastic gem) and force unique values. For example:
<select name="departure" size="1">
<option value="1">NY</option>
<option value="2">FL</option>
<option value="3">LA</option>
</select>
<select name="arrival" size="1">
<option value="1">NY</option>
<option value="2">FL</option>
<option value="3">LA</option>
</select>
The simplest way is to use jQuery, but I would like to know if there is any validation option in Rails 3 to handle such scenario. Thanks in advance!
You'll have to write your own I think.
validate :departure_cant_equal_arrival
def departure_cant_equal_arrival
if departure.present? and arrival.present? and (departure == arrival)
errors.add(:arrival, "can't be the same as departure")
end
end
Related
I have code with drop down menu. The object for this menu has few fields. Two of them are playerPosition and isFirstSquadPlayer.
If isFirstSquadPlayer is TRUE I need to display in menu player.playerPosition.
Trying on few ways but failed.
My controller:
public String players(#PathVariable long clubId, Model model) {
Club club = this.clubRepository.findByClubId(clubId);
model.addAttribute("players", this.playerRepository.findAllByPlayerClub(club));
return "players";
}
My HTML:
<select name="playerposition"
id="createnewplayerposition" th:value="${player.playerPosition}" required>
<option value="0">Select position for player</option>
<!--HERE NEED PROPER REQUEST -->
<option th:selected="${player.playerPosition}" th:text="${player.playerPosition}"></option>
<option value="GK">Goalkeeper</option>
<option value="RWB">Right Wingback</option>
<option value="RCB">Right Centreback</option>
(...)
</select>
as per kindly advice:
ok, tried and found such request with thymeleaf conditional:
<option th:if="${player.playerPosition!=null}" th:selected="${player.playerPosition}" th:text="${player.playerPosition}"></option>
it's not excactly how I expected but gives some solution –
please can help me.
I am trying to get the values of the "value" fields from my select_tag in rails and send it to the controller to use in variables to execute some commands, could help me follow my code.
This my view with 2 select_tags this is firsts select_tag one choice option and, go to second below
<select id="channel" name="channel"><option value="747">0800 0</option>
<option value="1750"> 0800 3</option>
<option value="1845"> 0800 1</option>
<option value="1839">0800 4</option>
<option value="1831">0800 5</option>
<option value="1326">08000 6</option>
<option value="1848">08000 7</option>
<option value="582">08000 8</option>
<option value="182">08000 9</option>
<option value="1838">0800 10</option></select>
This my view with the second select_tag choice one option with first select_tag.
<select id="opts" name="opts"><option value="578">opt 0</option>
<option value="470">opt 1</option>
<option value="577">opt 2</option>
<option value="600">opt 3</option>
<option value="539">opt 4</option></select>
i'm trying to get the values of the two select_tags on my controller i'm studying rails and ruby and i still couldn't do it could help me with my code
could show me how to receive these values in the controller I'm looking for examples
I have this select2 multi-selection dropdown that works fine on the client side but only posts the last selection users make:
<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-send" multiple="multiple">
<%= options_for_select( (::Transaction::SEND_METHODS).collect{ |m| [t(m[:name]), m[:name].parameterize ]}, selected: params[:payment_method] ) %>
</select>
It generates the following markup:
<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-receive" multiple="multiple">
<option value="coupons">Coupons</option>
<option value="paypal">Paypal</option>
<option value="skrill">Skrill</option>
<option value="revolut">Revolut</option>
<option value="zelle">Zelle</option>
<option value="transferwise">Transferwise</option>
<option value="swift-bank-transfer">SWIFT bank transfer</option>
<option value="european-bank-transfer">European bank transfer</option>
<option value="us-bank-transfer">US bank transfer</option>
<option value="uk-bank-transfer">UK bank transfer</option>
<option value="check">Check</option>
</select>
I've used this to initialize the control:
$( ".searchable-dropdown" ).select2({ theme: "bootstrap" });
After making several selections and sending the form, I am getting this within params:
"payment_methods":"paypal"
Paypal was indeed selected (last) but so were a bunch of other selections.
Was it not supposed to send them comma-separated or something? Am I doing something wrong?
Nevermind, looks like I wasn't asking Google the right question...
Multiple select box is not working in rails
You need to make sure that you are sending an array of answers by
changing the name to payment_methods[]
I got the following drop-down list - SELECT element - construction in my ZPT template:
<select id="record_selector">
<option tal:repeat="record view/records" tal:attributes="value record/id">
<span tal:replace="record/name"></span>
</option>
</select>
How make it possible to have selected OPTION which value is equal to one from the corresponding view property (i.e. for example, OPTION tag value == view/currentRecordId then make it selected).
Using the sdupton's clue, I got the following solution:
<select id="record_selector">
<tal:block tal:repeat="record view/records">
<option tal:condition="python: record['id'] != view.recordId"
tal:attributes="value record/id"
tal:content="record/name">
</option>
<option tal:condition="python: record['id'] == view.recordId"
tal:attributes="value record/id"
tal:content="record/name"
selected>
</option>
</tal:block>
</select>
TAL conditionals are awesome :)
I found another solution here: https://old.zope.org/Members/peterbe/DTML2ZPT/index.html#example14
This still works with Zope 5.3 on Python 3.
<select id="record_selector">
<option
tal:repeat="record view/records"
tal:attributes="
value record/id;
selected python: record['id'] == view.currentRecordId">
<span tal:replace="record/name"></span>
</option>
</select>
I have to Populate DropDown list of Country in MVC application. Where i have to make the Group as per the continent.. Any suggestion Help me alot Thanks
look how to do it in HTML
<select>
<optgroup label="G1">
<option value="c1">One</option>
</optgroup>
<optgroup label="G2">
<option value="s1">Two</option>
</optgroup>
</select>
u can implement by your own like here