We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 849
    • 19 Posts
    Hi, I have tried using template variables in form of dropdown selection, but discovered that the recently saved template variable on that field isn’t the one being selected when you re-edited the document, instead the first option is being selected instead. Is there anyway that this problem would be fixed in the backend? Or should I edit some code? Thanks in advance
      • 849
      • 19 Posts
      Just realized, I was using this format on options:
      option1
      ||option2
      ||option3

      And it(the \n) was trimmed on site_tmplvarcontents db table, so maybe the option2\n is being compared with option2 (without line break). Is this right?
        • 849
        • 19 Posts
        Ok here am I again answering my own question,
        My problem was:
        I used \n|| (line-break plus double pipe) on separating the options, but when storing the selected option on the database, it is being trimmed, removing the \n(line break). Now when the dropdown is being created, the field value (not trimmed), is being compared with the trimmed value, which won’t be equal. I edited
        /manager/includes/tmplvars.inc.php
        around line 250
        function ParseIntputOptions($v) {
        $a = array();
        if(is_array($v)) return $v;
        else if(is_resource($v)) {
        while ($cols = mysql_fetch_row($v)) $a[] = $cols;
        }
        else {
        $a = explode("||", $v);
        //Edited
        foreach ($a as $key=>$value) $a[$key] = trim($value); reset($a);

        }
        return $a;
        }


        edit: lol wait a minute, other options are being stripped...
        edit: it seems like the first option is being removed tongue
        edit: ok reset() made it work, the array pointer must have been pointing to the key 1 because of the added foreach.
          • 27179
          • 10 Posts
          I am attempting to do roughly the same thing, using TV’s and a dropdown to select, in my case, for example a genre or author for books.

          You get this working I would definitely be interested in how you did it.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I prefer to use a row of radio buttons or check boxes. Having said that, I don’t see the reason for having line breaks (or any other white space) in the delimiter for the options. You can even use a chunk to store your option list to make it easier to edit, and use @CHUNK in the options field.
              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
              • 849
              • 19 Posts
              Checkboxes and radio buttons would sound too hard to use on massive choices(around 50-100).

              The problem with not putting line breaks or whitespaces is that we can’t find it convenient for hundreds of choices. It will surely be an eyesore XD. I hope this would be a default behavior since it would be really helpful if the choices can be separated by whitespaces without worrying about problems like this, anyway there will be no problem with whitespaces (left and right) of the choices since it is really being trimmed before inserting it to the database, so it makes sense to trim it upon ParseIntputOptions(), right?

              Quote from: sidcypher at Jul 10, 2009, 11:48 PM

              I am attempting to do roughly the same thing, using TV’s and a dropdown to select, in my case, for example a genre or author for books.

              You get this working I would definitely be interested in how you did it.
              The bold’ed part(on my 3rd post) works, if you also have problems with the whitespaces between the choices, like
              option1
              ||option2
              ||option3.

              but if you don’t use this format I think you don’t need to edit it like I did
                • 26931
                • 2,314 Posts
                  • 849
                  • 19 Posts
                  I see, that is also good option, without editing anything on the source code, it would also be a friendlier solution for clients, to remove the || thing. thanks for the info.
                    • 7924
                    • 11 Posts
                    Quote from: albertdiones at Jun 24, 2009, 04:51 AM

                    ....
                    function ParseIntputOptions($v) {
                    $a = array();
                    if(is_array($v)) return $v;
                    else if(is_resource($v)) {
                    while ($cols = mysql_fetch_row($v)) $a[] = $cols;
                    }
                    else {
                    $a = explode("||", $v);
                    //Edited
                    foreach ($a as $key=>$value) $a[$key] = trim($value); reset($a);

                    }
                    return $a;
                    }



                    Great! Thanks!