We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Willi Waizenegger Reply #1, 14 years ago
    I'm missing something really obvious.

    What I'm trying to do is use the If component on a page to see whether a check box in the backend is checked (a checkbox TV) and, if it is checked, then show something on the front end.

    The checkbox TV is set up as follows:

    Name: news_event_checkbox_1
    Caption: News Event 1 Activate
    Input Options > Input Type: checkbox
    Input Options > Default Value: tried leaving it blank or adding the word 'no' in it.
    Output Type: Default
    Template Access: BaseTemplate

    The code on a page, which is added through a chunk, contains this:

    [[!If? &subject=`[[*news_event_checkbox_1]]` &operator=`empty` &then=`` &else=`                         
                              <li>
                                    <div>
                                        <img src="[[*news_image_1:phpthumbof=`&w=75&h=75&zc=1`]]" />
                                        <h3>[[*news_title_1]]</h3>
                                        <span>[[*date_time_1]]</span> - [[*news_summary_1]]
                                    </div>    
                                </li>
                        
                        `]]


    So, the idea is to make all that code appear on the page if the checkbox is checked in the backend. I'm sure I'm implementing the whole thing incorrectly. How do you use the checkbox TV? Is that kind of thing even what that checkbox Input Option is for?

    Also, the checkbox TV always seems to go back to the checked state in the backend, even after I save it as checked off. What gives?

    Running Revo v2.2.2-pl

    Thanks in advance. [ed. note: waizen last edited this post 14 years ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Checkboxes are either "yes" or "no", "empty" won't do the job.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 31902
        • 342 Posts
        Willi Waizenegger Reply #3, 14 years ago
        So, in other words, the code should look something like this:

        [[!If? &subject=`[[*news_event_checkbox_1]]` &operator=`no` &then=`` &else=`                        
                                  <li>
                                        <div>
                                            <img src="[[*news_image_1:phpthumbof=`&w=75&h=75&zc=1`]]" />
                                            <h3>[[*news_title_1]]</h3>
                                            <span>[[*date_time_1]]</span> - [[*news_summary_1]]
                                        </div>   
                                    </li>
                             
                            `]]


        Is that right? I'll try it here.

        Also, has anyone run into the second part of my question? The one about the checkbox always going back to being set as selected in the backend, even though the page was saved with the box being unchecked?
          • 3749
          • 24,544 Posts
          Try using 0 for the default value, though unchecking it and saving the resource should make it come up unchecked for that resource. The default value should only affect new resources.


          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I don't see where you've given it any Input Option Values...

            Activate==active


            The Default Value is what it should be even if it's never edited in a resource. Leave it blank if you want it unchecked; putting "active" there would make it checked by default.

            What do you get if you just put the TV tags in a content? When I gave it the above Input Option Values, when it's checked I get "active", when it's not checked I get nothing.

            If it doesn't have a value to return, it can't return anything!

            When it's unchecked, it doesn't even get posted, so it won't exist at all in the POST array.
            [ed. note: sottwell last edited this post 14 years ago.]
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 31902
              • 342 Posts
              Willi Waizenegger Reply #6, 14 years ago
              Thanks, Susan and Bob.

              I've tried leaving it blank and it always wants to keep itself checked, even if I uncheck it and save it. I would save it, go do other things and when I come back I find that it is checked again. I mean...really?


              As for having something in the Input Option Values area, I did try putting something in there, although I was never sure what that something should be. I naively added the word 'no' or '1'. Obviously, that was not it, not that I ever seriously expected that to work. I see that your suggestion of 'Activate==active' would be closer to what I need?

              In the end, instead of a checkbox, I did the following:

              1. I created an Input Type of Listbox (Single-Select).
              2. In the Input Option Values, I added

              No==1||Yes==2


              3. Not sure if I need it, but in the Output Options > Output Type, I set it to 'Delimiter'.

              4. In the Output Options > Delimiter field, I added '||'

              5. In the page code, I added this:

              [[!If? &subject=`[[*news_event_checkbox_1]]` &operand=`1` &then=`` &else=`                       
                                        <li>
                                              <div>
                                                  <img src="[[*news_image_1:phpthumbof=`&w=75&h=75&zc=1`]]" />
                                                  <h3>[[*news_title_1]]</h3>
                                                  <span>[[*date_time_1]]</span> - [[*news_summary_1]]
                                              </div>  
                                          </li>
                                    
                                  `]]


              ...notice that I changed the

              &operator=`no`


              to

               &operand=`1`


              All that worked great. So, it is now not working as a check box but, rather, as a yes/no dropdown, which is okay for now.

              However, I would still like to figure out the checkbox thing for future applications.

              Doing some searches, I found several bug reports (old ones) regarding the checkbox staying checked, although I'm not ready to definitely suggest this is what is happening here. It's still in the back of my head, though. I'm sure it's something I'm not setting correctly. [ed. note: waizen last edited this post 14 years ago.]