Options 'selected' (pre populate form)
I have a problem with the Slim template engine in a Sinatra project. I
have an edit form. I require the form to be filled when the route is
triggered. There is an issue with HTML select option. I need something
like this when the edit form is loaded. Notice that Mrs. option is
selected:
<select name="person[title]" id="person[title]">
<option value="Mr.">Mr.</option>
<option value="Mrs." selected>Mrs.</option>
</select>
I tried:
option[value="Mrs." "#{person.title == :mrs ? 'selected' : ''}"]
The exception was about an attribute error. Then I tried something like this:
option[value="Mrs." selected="#{person.title == :mrs ? true : false}"]
but then the output was something like this:
<option value"Mrs." selected="false">Mrs.</option>
I guess the string"false" is interpreted as true. That failed. I tried
some combinations with round brackets but couldn't get it to work.
How could I set the selected attribute of an option in a select list in Slim?
No comments:
Post a Comment