We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27106
    • 147 Posts
    It is possible to use the NewsPublisher snippet (http://bobsguides.com/newspublisher-tutorial.html) with an auto-tag TV input type.

    However, it's not obvious how you'd recreate in NewsPublisher the terrific UI device that appears in the MODx manager. The manager interface lets you add commonly-used tags by clicking on them below the text field, and it automatically adds new tags to the list of tags that are available.

    Has anyone been able to adapt NewsPublisher to do this?
      David Walker
      Principal, Shorewalker DMS
      Phone: 03 8899 7790
      Mobile: 0407 133 020
      • 3749
      • 24,544 Posts
      Not me. wink
        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
        • 42562
        • 1,145 Posts
        Just realized that I too needed this feature. Oh dear!
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 3749
          • 24,544 Posts
          There is JS code in Notify that does that. The possible tags are in a chunk, though I don't think the chunk is ever updated and I don't think there's any way for the user to type in a tag.

          Here'e the code if anyone wants to try to use it in Notify. I won't get to it any time soon.

          /**
               * Gets the possible tags from the preList Tpl chunk and, if not empty,
               * injects the HTML and JS code to let user add tags by clicking on the buttons
               */
              protected function setTags() {
                  $tags = '';
                  $tagChunkName = $this->modx->getOption('prefListChunkName', $this->props, 'sbsPrefListTpl');
                  $tagList = $this->modx->getChunk($tagChunkName);
                  if (!empty($tagList)) {
          
                      $src = '<script type="text/javascript">
          function nf_insert_tag(tag) {
              var text = document.getElementById("nf_tags").value;
              if (text.indexOf(tag) != -1) {
                 text= text.replace("," + tag + ",","," );
                 text = text.replace(tag + ",","");
                 text = text.replace("," + tag,"");
                 text = text.replace(tag,"");
              } else {
                  if (text) {
                  text = text + "," + tag;
                  } else {
                    text = tag;
                  }
              }
              var tagArray = text.split(",");
              tagArray.sort();
              text = tagArray.join(",");
              document.getElementById("nf_tags").value = text;
          return false;
              }
          </script>';
          
                      $this->modx->regClientStartupScript($src);
                      $tags = '<p>';
                      $tagArray = explode('||', $tagList);
                      natcasesort($tagArray);
                      $i = 0;
                      foreach ($tagArray as $t) {
                          $t = strtolower($t);
                          $pos = strpos($t, '==');
                          $tag = $pos ? substr($t, $pos + 2) : $t;
                          $tag = trim($tag);
                          $tags .= '<button name="button' . $i . '" id="button' . $i . '" type="button" class="nf_tag" onclick="nf_insert_tag(' . "'" . $tag . "'" . ');"' . '">' . $tag . "</button>\n";
                          $i++;
                      }
                      $tags .= '</p>';
                  }
                  $this->modx->setPlaceholder('nf_tag_list', $tags);
              }
          [ed. note: BobRay last edited this post 10 years, 4 months ago.]
            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
            • 31196
            • 17 Posts
            Hey,
            I also wanted to list the available tags as toggle buttons underneath the textfield and found a quick way to achieve this. It does however depend on the tagLister Extra so you need to install that first.

            Then in core/components/newspublisher/model/newspublisher/newspublisher.class.php around line 858 add this:

            case 'autotag':
                            $formTpl .= $this->_displaySimple($name, 'TagOuterTpl', '');
                            break;

            Note that the template name 'TagOuterTpl' does not include the prefix 'np'.

            Back in the manager you create a chunk called 'npTagOuterTpl' with this code:
            <div id="np-[[+npx.fieldName]]-container" class="np-text">
              [[+np.error_[[+npx.fieldName]]]]
              <label class="fieldlabel" for="np-[[+npx.fieldName]]" [[+npx.readonly]] title="[[+npx.help]]">[[+npx.caption]]: </label>
              <input name="[[+npx.fieldName]]" class="text" id="np-[[+npx.fieldName]]" type="text"  value="[[+np.[[+npx.fieldName]]]]"  maxlength="[[+npx.maxlength]]" />
            </div>
            
            [[!tagLister? &tv=`tags` &tpl=`npTagTpl` &parents=`1` &limit=`100`]]
            
            <script>
            function toggleTag(t){
              var val = document.getElementById("np-[[+npx.fieldName]]").value;
              var tags = val ? val.split(',') : [];
              var index = tags.indexOf(t);
              if(index > -1){
                tags.splice(index, 1);
              }else{
                tags.push(t);
              }
              document.getElementById("np-[[+npx.fieldName]]").value = tags.join(',');
            }
            </script>


            And then another chunk called 'npTagTpl':
            <button class="toggleTag" type="button" name="toggleTag-[[+tag]]" onclick="toggleTag('[[+tag]]')">[[+tag]]</button>


            I think that was it. I haven't tested it extensively yet but it seems to work...

            Edit: I just realised that since the tagLister snippet is for front-end use it only lists tags of published resources .. had me puzzled for a while [ed. note: vacatoro last edited this post 10 years, 4 months ago.]
              • 3749
              • 24,544 Posts
              Nice. smiley

              I'm confused about the chunk names. Shouldn't the chunk referenced in the case statement be 'npTagOuterTpl'? I don't see that chunk being used in your code. Maybe I'm missing something.
                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
                • 31196
                • 17 Posts
                Hi Bob,
                I assume the prefix "np" is added at some point later in the code. With the "np" in the beginning the chunk is not found.

                I just followed the logic of the other case statements:

                case 'number':
                                $formTpl .= $this->_displaySimple($name, 'IntTpl', $this->intMaxlength);
                                break;
                
                  • 3749
                  • 24,544 Posts
                  That sounds right. It's been quite a while since I looked at the code. Thanks for clarifying. wink
                    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
                    • 31196
                    • 17 Posts
                    Thanks for the NewsPublisher extra smiley
                      • 3749
                      • 24,544 Posts
                      You're welcome. I wish I had time to update it.
                        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