How can I force Visualforce to include empty attributes which I have specified?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite












During my adventures trying to get a <select required="required"> to actually be required, I discovered:




If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1; and if the value of the first option element in the select element's list of options (if any) is the empty string, and that option element's parent node is the select element (and not an optgroup element), then that option is the select element's placeholder label option.




So I changed my markup to mirror that:



<select required="required" ...>
<option value="">--</option>
...
</select>


But unfortunatley it rendered as:



<select required="required" ...>
<option>--</option>
...
</select>


And because value="" was stripped out, it no longer meets the specification for <select required="required">, and the form can be submitted with no value selected.



How can I get the value="" attribute specification to stick?










share|improve this question



























    up vote
    4
    down vote

    favorite












    During my adventures trying to get a <select required="required"> to actually be required, I discovered:




    If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1; and if the value of the first option element in the select element's list of options (if any) is the empty string, and that option element's parent node is the select element (and not an optgroup element), then that option is the select element's placeholder label option.




    So I changed my markup to mirror that:



    <select required="required" ...>
    <option value="">--</option>
    ...
    </select>


    But unfortunatley it rendered as:



    <select required="required" ...>
    <option>--</option>
    ...
    </select>


    And because value="" was stripped out, it no longer meets the specification for <select required="required">, and the form can be submitted with no value selected.



    How can I get the value="" attribute specification to stick?










    share|improve this question























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      During my adventures trying to get a <select required="required"> to actually be required, I discovered:




      If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1; and if the value of the first option element in the select element's list of options (if any) is the empty string, and that option element's parent node is the select element (and not an optgroup element), then that option is the select element's placeholder label option.




      So I changed my markup to mirror that:



      <select required="required" ...>
      <option value="">--</option>
      ...
      </select>


      But unfortunatley it rendered as:



      <select required="required" ...>
      <option>--</option>
      ...
      </select>


      And because value="" was stripped out, it no longer meets the specification for <select required="required">, and the form can be submitted with no value selected.



      How can I get the value="" attribute specification to stick?










      share|improve this question













      During my adventures trying to get a <select required="required"> to actually be required, I discovered:




      If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1; and if the value of the first option element in the select element's list of options (if any) is the empty string, and that option element's parent node is the select element (and not an optgroup element), then that option is the select element's placeholder label option.




      So I changed my markup to mirror that:



      <select required="required" ...>
      <option value="">--</option>
      ...
      </select>


      But unfortunatley it rendered as:



      <select required="required" ...>
      <option>--</option>
      ...
      </select>


      And because value="" was stripped out, it no longer meets the specification for <select required="required">, and the form can be submitted with no value selected.



      How can I get the value="" attribute specification to stick?







      visualforce html html5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Adrian Larson♦

      101k19108228




      101k19108228




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote













          Here is another way to do it w/o javascript:



          Set the value to a VisualForce function that evaluates to nothing:



          <apex:page standardController="Contact" >
          <apex:form>
          <select required="required">
          <option value="!IF(1=1,'','')">--</option>
          <option value="1">Option 1</option>
          <option value="2">Option 2</option>
          </select>
          <apex:commandButton value="Test Submit" action="!save" />
          </apex:form>




          It will send the value attribute to the browser:
          HTML in browser



          The browser will require it now:



          Required on form submit






          share|improve this answer




















          • I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
            – Adrian Larson♦
            20 mins ago


















          up vote
          0
          down vote













          It's ugly, but below is the workaround I found. I would be happy to find one which does not require Javascript.



          Since I already had a page load listener, I simply appended to it:



          (function (w) 
          "use strict";
          w.addEventListener("load", function ()
          .forEach.call(
          document.querySelectorAll("option:not([value])"),
          function (element) element.value = '';
          );

          )(window);





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235668%2fhow-can-i-force-visualforce-to-include-empty-attributes-which-i-have-specified%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            Here is another way to do it w/o javascript:



            Set the value to a VisualForce function that evaluates to nothing:



            <apex:page standardController="Contact" >
            <apex:form>
            <select required="required">
            <option value="!IF(1=1,'','')">--</option>
            <option value="1">Option 1</option>
            <option value="2">Option 2</option>
            </select>
            <apex:commandButton value="Test Submit" action="!save" />
            </apex:form>




            It will send the value attribute to the browser:
            HTML in browser



            The browser will require it now:



            Required on form submit






            share|improve this answer




















            • I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
              – Adrian Larson♦
              20 mins ago















            up vote
            4
            down vote













            Here is another way to do it w/o javascript:



            Set the value to a VisualForce function that evaluates to nothing:



            <apex:page standardController="Contact" >
            <apex:form>
            <select required="required">
            <option value="!IF(1=1,'','')">--</option>
            <option value="1">Option 1</option>
            <option value="2">Option 2</option>
            </select>
            <apex:commandButton value="Test Submit" action="!save" />
            </apex:form>




            It will send the value attribute to the browser:
            HTML in browser



            The browser will require it now:



            Required on form submit






            share|improve this answer




















            • I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
              – Adrian Larson♦
              20 mins ago













            up vote
            4
            down vote










            up vote
            4
            down vote









            Here is another way to do it w/o javascript:



            Set the value to a VisualForce function that evaluates to nothing:



            <apex:page standardController="Contact" >
            <apex:form>
            <select required="required">
            <option value="!IF(1=1,'','')">--</option>
            <option value="1">Option 1</option>
            <option value="2">Option 2</option>
            </select>
            <apex:commandButton value="Test Submit" action="!save" />
            </apex:form>




            It will send the value attribute to the browser:
            HTML in browser



            The browser will require it now:



            Required on form submit






            share|improve this answer












            Here is another way to do it w/o javascript:



            Set the value to a VisualForce function that evaluates to nothing:



            <apex:page standardController="Contact" >
            <apex:form>
            <select required="required">
            <option value="!IF(1=1,'','')">--</option>
            <option value="1">Option 1</option>
            <option value="2">Option 2</option>
            </select>
            <apex:commandButton value="Test Submit" action="!save" />
            </apex:form>




            It will send the value attribute to the browser:
            HTML in browser



            The browser will require it now:



            Required on form submit







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 26 mins ago









            HungryBeagle

            39518




            39518











            • I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
              – Adrian Larson♦
              20 mins ago

















            • I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
              – Adrian Larson♦
              20 mins ago
















            I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
            – Adrian Larson♦
            20 mins ago





            I prefer IF(true,...) to IF(1=1,...). Regardless, it is much better to avoid javascript than what I came to on my own.
            – Adrian Larson♦
            20 mins ago













            up vote
            0
            down vote













            It's ugly, but below is the workaround I found. I would be happy to find one which does not require Javascript.



            Since I already had a page load listener, I simply appended to it:



            (function (w) 
            "use strict";
            w.addEventListener("load", function ()
            .forEach.call(
            document.querySelectorAll("option:not([value])"),
            function (element) element.value = '';
            );

            )(window);





            share|improve this answer
























              up vote
              0
              down vote













              It's ugly, but below is the workaround I found. I would be happy to find one which does not require Javascript.



              Since I already had a page load listener, I simply appended to it:



              (function (w) 
              "use strict";
              w.addEventListener("load", function ()
              .forEach.call(
              document.querySelectorAll("option:not([value])"),
              function (element) element.value = '';
              );

              )(window);





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                It's ugly, but below is the workaround I found. I would be happy to find one which does not require Javascript.



                Since I already had a page load listener, I simply appended to it:



                (function (w) 
                "use strict";
                w.addEventListener("load", function ()
                .forEach.call(
                document.querySelectorAll("option:not([value])"),
                function (element) element.value = '';
                );

                )(window);





                share|improve this answer












                It's ugly, but below is the workaround I found. I would be happy to find one which does not require Javascript.



                Since I already had a page load listener, I simply appended to it:



                (function (w) 
                "use strict";
                w.addEventListener("load", function ()
                .forEach.call(
                document.querySelectorAll("option:not([value])"),
                function (element) element.value = '';
                );

                )(window);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                Adrian Larson♦

                101k19108228




                101k19108228



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235668%2fhow-can-i-force-visualforce-to-include-empty-attributes-which-i-have-specified%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    What does second last employer means? [closed]

                    One-line joke