Ruby on Rails/HTML - Inline forms :checked => false is not working










0















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.










share|improve this question
























  • <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















0















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.










share|improve this question
























  • <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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 2:22









Homam

192




192










asked Nov 13 '18 at 23:01









JamesWuJamesWu

77112




77112












  • <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
















<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












2 Answers
2






active

oldest

votes


















0














Have you tried to set :checked => true in your 'No' label?



<%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>





share|improve this answer























  • 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



















0














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:



enter image description here



You can see a example of input type checkbox with checked html5 attribute on w3schools.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    Have you tried to set :checked => true in your 'No' label?



    <%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>





    share|improve this answer























    • 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
















    0














    Have you tried to set :checked => true in your 'No' label?



    <%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>





    share|improve this answer























    • 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














    0












    0








    0







    Have you tried to set :checked => true in your 'No' label?



    <%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>





    share|improve this answer













    Have you tried to set :checked => true in your 'No' label?



    <%= label(:store_item, :can_be_shipped, 'No', :value => false, :checked => true)%>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 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


















    • 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

















    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














    0














    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:



    enter image description here



    You can see a example of input type checkbox with checked html5 attribute on w3schools.






    share|improve this answer



























      0














      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:



      enter image description here



      You can see a example of input type checkbox with checked html5 attribute on w3schools.






      share|improve this answer

























        0












        0








        0







        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:



        enter image description here



        You can see a example of input type checkbox with checked html5 attribute on w3schools.






        share|improve this answer













        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:



        enter image description here



        You can see a example of input type checkbox with checked html5 attribute on w3schools.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 22 '18 at 11:20









        decabezadecabeza

        214




        214



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3