My template file:
{{range $index, $option := .alternatives}}
<div id="splashAlternative{{$index}}" class="col-sm-2">
<select id="flashSrc_{{$index}}">
{{template "alternative_src.html" $option}}
</select>
</div>
{{end}}
I want pass $option to template, and alternative_src.html code :
{{if compare .option ""}}
<option value="" selected="selected">
</option>
{{else}}
<option value=""></option>
{{end}}
{{if compare .option "xxx"}}
<option value="xxx" selected="selected">xxx</option>
{{else}}
<option value="xxx">xxx</option>
{{end}}
but I get problem below:
executing "alternative_src.html" at <.option>: can't evaluate field option in type string
When you use the {{template}} action and you pass something, that becomes the dot . in the called template. Quoting from the package doc of text/template:
{{template "name" pipeline}}
The template with the specified name is executed with dot set
to the value of the pipeline.
So inside alternative_src.html refer to the option only as a dot . (the dot . will mean the value of the pipeline you passed to the template, which is $option in the caller template):
{{if compare . ""}}
<option value="" selected="selected">
</option>
{{else}}
<option value=""></option>
{{end}}
{{if compare . "xxx"}}
<option value="xxx" selected="selected">xxx</option>
{{else}}
<option value="xxx">xxx</option>
{{end}}
Related
Here is my Multiselect
<div class="form-group">
<label>Multiple select using select 2</label>
<select class="js-example-basic-multiple w-100" id='mls' name="resources" multiple="multiple">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
<option value="AM">America</option>
<option value="CA">Canada</option>
<option value="RU">Russia</option>
</select>
</div>
Whenever I try to post despite selecting multiple values I still get only one .
Here is stacktrace.
Variable Value
csrfmiddlewaretoken
'aI5tuSxOtxzGOpMDKR4RcH685yWUFpqkgTeBrYVbQ8kN9ODxnPOytllMTAb11Bib'
acc_id
'1'
resources
'AM'
I tried with getlist as well still getting single value we all can see single values are passing in request itself.
Not sure what might I am doing wrong here .
It seems you are send single value from front.
i tested it:
<form method="GET">
<div class="form-group">
<label>Multiple select using select 2</label>
<select class="js-example-basic-multiple w-100" id='mls' name="resources" multiple="multiple">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
<option value="AM">America</option>
<option value="CA">Canada</option>
<option value="RU">Russia</option>
</select>
</div>
<button type="submit">Show me markers</button>
</form>
i see in request:
"GET /test/testmarkers/?resources=WY&resources=AM HTTP/1.1" 200 1867
And i am sure, you are use not Form.send(). How are you send it?
How to get the value from the dropDown Box in Django Without Submit Button
<div class="single-shorter">
<form action="." method="GET">
<label>Sort By :</label>
<select name="val" id="val">
<option selected="selected" value="name">Name</option>
<option value="price">Price</option>
</select>
</form>
</div>
You can simple obtain it using Ajax but as mentioned in comments in dont want to use that u can use value attribute in option value and using event listner and window.loction.href we can obtain this... This is one example
<select id="foo">
<option value="">Your Dropdown</option>
<option value="http://www.google.com">x</option>
<option value="http://www.facebook.com">y</option>
</select>
<script>
document.getElementById("foo").onchange = function() {
if (this.selectedIndex!==0) {
window.location.href = this.value;
}
};
</script>
as u are using django use this and also dont want to change the value attribute
<select id="my_selection">
<option value="x" href="/link/to/somewhere">value 1</option>
<option value="y" href="/link/to/somewhere/else">value 2</option>
</select>
<script>
document.getElementById('my_selection').onchange = function() {
window.location.href = this.children[this.selectedIndex].getAttribute('href');
}
</script>
I am building a dashboard which will have some information about users. I am trying to set value to select tag using Django but the value never get assigned. Here is my code.
My model look something like this
class User(models.Model):
first_name
last_name
reg_status
I need to fill in the template with the reg_status. The reg_status can contain three options, they are as mentioned below:
mailed
register
not register
The value of reg_status is dynamic. For example, if I pass in reg_status = mailed from my view, I need the <option value='mailed'> to be selected. However, if I pass in the reg_status = register from my view, I need the <option value='register'> to be selected.
Here is how I am trying to render the content in the template:
{% for u in user %}
<input type='text' value={{u.first_name}}/>
<input type='text' value={{u.last_name}}/>
<select value={{u.reg_status}>
<option value='mailed'>mailed</option>
<option value='register'>register</option>
<option value='not register'>not register</option>
</select>
{% endfor %}
The output give 'mailed' as selected for all instance even if the value is set to 'registered' or 'not registered'.
You can use a Jinja ternary operator. It's a little greedy because you're doing the same operation 3 times. You could also look into setting a global variable with Jinja (see the documentation, scroll down to Scoping Behavior).
<select value='{{ u.reg_status }}'>
<option value='mailed' {{ "selected='selected'" if u.reg_status == 'mailed' else "" }}>mailed</option>
<option value='register' {{ "selected='selected'" if u.reg_status == 'register' else "" }}>register</option>
<option value='not register' {{ "selected='selected'" if u.reg_status == 'not register' else "" }}>not register</option>
</select>
I have to change the style of the following dropdown select menu:
<form>
<div class="ui-field-contain">
<label for="select-native-1">Basic:</label>
<select name="select-native-1" id="select-native-1">
<option value="1">The 1st Option</option>
<option value="2">The 2nd Option</option>
<option value="3">The 3rd Option</option>
<option value="4">The 4th Option</option>
</select>
</div>
</form>
all the option should display as list under the label (like Accordion list)
I need some help ...
I need the location drop down box to determine the appropriate inbox the form should be sent to.
ex if I choose Houston from the drop down box it will send it to the PayrollUSA email.
Im currently using a radio button to make the selection but i would like to automate with the drop down.
Im pretty new to this but im sure theres a if statement that can tie them together...
im using .asp for this.
<input type="radio" name="payroll" value="PayrollUSA#mail.com" checked="checked">US Payroll
<input type="radio" name="payroll" value="PayrollCAN#mail.com">CAN Payroll
<input type="radio" name="payroll" value="PayrollUK#mail.com">UK Payroll
<input type="radio" name="payroll" value="PayrollHK#mail.com">HK Payroll
Drop down selection
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option selected >Select</option>
<OPTION>Calgary</OPTION>
<OPTION>Chicago</OPTION>
<OPTION>Hong Kong</OPTION>
<OPTION>Houston</OPTION>
<OPTION>London</OPTION>
<OPTION>Los Angeles</OPTION>
<OPTION>Montreal</OPTION>
<OPTION>New York</OPTION>
<OPTION>New York Corporate</OPTION>
<OPTION>Philadelphia</OPTION>
<OPTION>San Francisco</OPTION>
<OPTION>Toronto</OPTION>
<OPTION>Toronto Corporate</OPTION>
<OPTION>Vancouver</OPTION>
</SELECT>
If you need the option value to be held then try this:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="">Select an Option</option>
<option <% if Business_Unit= "PayrollCAN#mail.com" then %> selected <% End if %> value="PayrollCAN#mail.com">Calgary</option>
<option <% if Business_Unit= "PayrollUSA#mail.com" then %> selected <% End if %> value="PayrollUSA#mail.com">Chicago</option>
</select>
etc. for each option and same value may be used for different option displays
I imaging this should just be html based. So your option menu should look like:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="-1">Select an Option</option>
<OPTION value="PayrollCAN#mail.com">Calgary</OPTION>
<OPTION value="PayrollUSA#mail.com">Chicago</OPTION>
<OPTION value="PayrollHK#mail.com">Hong Kong</OPTION>
<OPTION value="PayrollUSA#mail.com">Houston</OPTION>
<OPTION value="PayrollUK#mail.com">London</OPTION>
<OPTION value="PayrollUSA#mail.com">Los Angeles</OPTION>
<OPTION value="PayrollCAN#mail.com">Montreal</OPTION>
<OPTION value="PayrollUSA#mail.com">New York</OPTION>
<OPTION value="PayrollUSA#mail.com">New York Corporate</OPTION>
<OPTION value="PayrollUSA#mail.com">Philadelphia</OPTION>
<OPTION value="PayrollUSA#mail.com">San Francisco</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto Corporate</OPTION>
<OPTION value="PayrollCAN#mail.com">Vancouver</OPTION>
</SELECT>
You can use the same value multiple times if needed