Ruby on Rails/HTML - Inline forms :checked => false is not working
What I want:
I want the default option for this form to be "No" (or false), and yet when I set it as the above, my app loads with no option chosen.
When I do :check => true
, the default option selected is "Yes" (or true), so I figured switching to false and move it to the No option would work, yet it doesn't.
Relevant code:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => false)%>
</div>
</div>
</div
What should I be doing here so the default option checked is "No" (false)?
Thank you.
html css ruby-on-rails
add a comment |
What I want:
I want the default option for this form to be "No" (or false), and yet when I set it as the above, my app loads with no option chosen.
When I do :check => true
, the default option selected is "Yes" (or true), so I figured switching to false and move it to the No option would work, yet it doesn't.
Relevant code:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => false)%>
</div>
</div>
</div
What should I be doing here so the default option checked is "No" (false)?
Thank you.
html css ruby-on-rails
<label>
s don't havevalue
orchecked
attributes, they havefor
attributes which reference the radio button which does have those attributes.
– mu is too short
Nov 13 '18 at 23:25
add a comment |
What I want:
I want the default option for this form to be "No" (or false), and yet when I set it as the above, my app loads with no option chosen.
When I do :check => true
, the default option selected is "Yes" (or true), so I figured switching to false and move it to the No option would work, yet it doesn't.
Relevant code:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => false)%>
</div>
</div>
</div
What should I be doing here so the default option checked is "No" (false)?
Thank you.
html css ruby-on-rails
What I want:
I want the default option for this form to be "No" (or false), and yet when I set it as the above, my app loads with no option chosen.
When I do :check => true
, the default option selected is "Yes" (or true), so I figured switching to false and move it to the No option would work, yet it doesn't.
Relevant code:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => false)%>
</div>
</div>
</div
What should I be doing here so the default option checked is "No" (false)?
Thank you.
html css ruby-on-rails
html css ruby-on-rails
edited Nov 14 '18 at 2:22
Homam
192
192
asked Nov 13 '18 at 23:01
JamesWuJamesWu
77112
77112
<label>
s don't havevalue
orchecked
attributes, they havefor
attributes which reference the radio button which does have those attributes.
– mu is too short
Nov 13 '18 at 23:25
add a comment |
<label>
s don't havevalue
orchecked
attributes, they havefor
attributes which reference the radio button which does have those attributes.
– mu is too short
Nov 13 '18 at 23:25
<label>
s don't have value
or checked
attributes, they have for
attributes which reference the radio button which does have those attributes.– mu is too short
Nov 13 '18 at 23:25
<label>
s don't have value
or checked
attributes, they have for
attributes which reference the radio button which does have those attributes.– mu is too short
Nov 13 '18 at 23:25
add a comment |
2 Answers
2
active
oldest
votes
Have you tried to set :checked => true
in your 'No' label?
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:store_item.can_be_shipped
returnstrue
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…
– Gabriel Klockner
Nov 14 '18 at 1:05
add a comment |
It seems you are set :checked => true
in your label, but you need set this attribute on your radio_button
.
If you want the default option for this form to be "No" the correct code it would be:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false, :checked => true)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false)%>
</div>
</div>
</div>
This generate a form with "No" as default checked option:
You can see a example of input type checkbox with checked
html5 attribute on w3schools.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290797%2fruby-on-rails-html-inline-forms-checked-false-is-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have you tried to set :checked => true
in your 'No' label?
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:store_item.can_be_shipped
returnstrue
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…
– Gabriel Klockner
Nov 14 '18 at 1:05
add a comment |
Have you tried to set :checked => true
in your 'No' label?
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:store_item.can_be_shipped
returnstrue
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…
– Gabriel Klockner
Nov 14 '18 at 1:05
add a comment |
Have you tried to set :checked => true
in your 'No' label?
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>
Have you tried to set :checked => true
in your 'No' label?
<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>
answered Nov 13 '18 at 23:45
Gabriel KlocknerGabriel Klockner
34
34
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:store_item.can_be_shipped
returnstrue
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…
– Gabriel Klockner
Nov 14 '18 at 1:05
add a comment |
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:store_item.can_be_shipped
returnstrue
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…
– Gabriel Klockner
Nov 14 '18 at 1:05
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
Hi Gabriel, thanks for your comment. I've just done that now, and annoyingly it still doesn't work.
– JamesWu
Nov 14 '18 at 0:01
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:
store_item.can_be_shipped
returns true
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…– Gabriel Klockner
Nov 14 '18 at 1:05
I guess that your object is returning the first radio button value (third parameter, true), and because of that it always returns checked. Example:
store_item.can_be_shipped
returns true
and it always checks the radio button that matches. In your case the first one. Here is the code where radio_button is implemented inside rails, maybe this documentation can help you: github.com/rails/rails/blob/master/actionview/lib/action_view/…– Gabriel Klockner
Nov 14 '18 at 1:05
add a comment |
It seems you are set :checked => true
in your label, but you need set this attribute on your radio_button
.
If you want the default option for this form to be "No" the correct code it would be:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false, :checked => true)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false)%>
</div>
</div>
</div>
This generate a form with "No" as default checked option:
You can see a example of input type checkbox with checked
html5 attribute on w3schools.
add a comment |
It seems you are set :checked => true
in your label, but you need set this attribute on your radio_button
.
If you want the default option for this form to be "No" the correct code it would be:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false, :checked => true)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false)%>
</div>
</div>
</div>
This generate a form with "No" as default checked option:
You can see a example of input type checkbox with checked
html5 attribute on w3schools.
add a comment |
It seems you are set :checked => true
in your label, but you need set this attribute on your radio_button
.
If you want the default option for this form to be "No" the correct code it would be:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false, :checked => true)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false)%>
</div>
</div>
</div>
This generate a form with "No" as default checked option:
You can see a example of input type checkbox with checked
html5 attribute on w3schools.
It seems you are set :checked => true
in your label, but you need set this attribute on your radio_button
.
If you want the default option for this form to be "No" the correct code it would be:
<div class="form-group">
<%= label(:store_item, :can_be_shipped, 'Can be Shipped?')%>
<div class="form-inline">
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, true)%>
<%= label(:store_item, :can_be_shipped, 'Yes', :value => true)%>
</div>
<div class="radio inline">
<%= radio_button(:store_item, :can_be_shipped, false, :checked => true)%>
<%= label(:store_item, :can_be_shipped, 'No', :value => false)%>
</div>
</div>
</div>
This generate a form with "No" as default checked option:
You can see a example of input type checkbox with checked
html5 attribute on w3schools.
answered Dec 22 '18 at 11:20
decabezadecabeza
214
214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290797%2fruby-on-rails-html-inline-forms-checked-false-is-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
<label>
s don't havevalue
orchecked
attributes, they havefor
attributes which reference the radio button which does have those attributes.– mu is too short
Nov 13 '18 at 23:25