We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38047
    • 32 Posts
    This one should be easy but I can't quite figure it (more of a designer learning to be a developer thatn a developer. )
    I have the start of a menu which thirteen items in an unordered list..
    <ul>
    	<li>All Vehicles</li>
    	<li>Buses</li>
    	<li>Chiller Trucks</li>
    	<li>Crane Trucks</li>
    	<li>Dual Cab Trucks</li>
    	<li>Box & Curtain Sider Trucks</li>
    	<li>Tilt & Slide Trucks</li>
    	<li>Tipper Trucks</li>
    	<li>Tray Top Trucks</li>
    	<li>Car License Trucks</li>
    	<li>Other</li>
    	<li>Cars/Vans/Utes</li>
    	<li>As Traded</li>
    </ul>
    

    And a template variable available to my stock list, checkbox input type, with the 13 options in the Input Options and 'All Vehicles' selected as default : -

    All Vehicles||Buses||Chiller Trucks||Crane Trucks||Dual Cab Trucks||Box Curtain Sider Trucks||Tilt Slide Trucks||Tipper Trucks||Tray Top Trucks||Car License Trucks||Other||Cars Vans Utes||As Traded

    The user can check as many boxes as they like, what would the best way to link the unordered list items to output resources with the checkbox ticked? Do I need the 'All Vehicles' checkbox? I would guess I don't really.

    I just feel that I could spend all day going around in circles on this one when someone else could tell me in a few lines how to go about it, thanks in advance, my client is baying for my blood........... (not really but I'd like to get a solution today)

    Phil [ed. note: philsdesign last edited this post 11 years, 9 months ago.]
    • So if I understand correctly, you want to have the visitor see the list, but with one already checked which the resource editor checked.

      You'll need to set the checked="checked" attribute according to that actual value of the resource's TV. You'll need an if() condition to check each one to see if it matches the actual TV value as you loop through the array. Something like

      $array = array('one', 'two', 'three');
      $tvValue = $modx->resource->getTVValue('foo');
      $checked = '';
      foreach($array as $item) {
              if($item == $tvValue) { $checked = ' checked="checked"'; }
              $output .= 'input type="checkbox" name="whatever[]" value=". $item . $checked>'.$item;
      }
      
      return $output;
      

      [ed. note: sottwell last edited this post 11 years, 9 months 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
        • 28120
        • 380 Posts
        Why don't you have the 12 tick boxes (excluding All Vehicles) and then have an option "Select All | De-Select All"
          • 38047
          • 32 Posts
          Thank you both for your prompt replies. Let me explain a little better - the checkboxes are available in the manager, to the person who is adding a stock item resource (i.e. a vehicle) for categorising.

          Every vehicle is obviously included within the category all vehicles.

          The unordered list is a menu on the web site, so when the customer clicks on say for example 'Box & Curtain Sider Trucks' they will get al list of all matching vehicles, but a truck like that may also be available as a 'car license truck' (one you can drive without a special license).

          The visitor will not see the check boxes, just the menu, but the Box/Curtainsider truck will appear under 'All Vehicles', 'Box & Curtain Sider Trucks' and 'Car License Trucks' so it's a one to many relationship. With my limited knowledge of php that looks like the kind of thing Susan - i'm not asking you to write the thing for me but with my tv ('category') being a checkbox input, would I end up with an array for the snippet; could you explain a little more please if you have the time?

          • Sounds more like a job for category tags. http://forums.modx.com/index.php?topic=58916.0
              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