Changing labels / hiding elements in specific categories

Technical Support
  • I have one specific category in which I wish to change button label "New topic" to "Ask a question". Similar for hiding tag manager. I wish to hide it in this specific category, but I want it visible in all other categories. I managed to hide tag manager in general, but that isn't the solution I'm looking for.

  • The body tag should have a class for each category. You could use some js in the custom header to change the new topic text:

    <script>
    $(window).on('action:ajaxify.contentLoaded', function(){
      $('.page-category-16 [component="category/post"]').text('Ask a Question')
    })
    </script>
    

    You can use the same class to hide the tags manager in custom css:

    .page-category-16 .tags-container {
      display: "none";
    }
    
  • Great! I didn't noticed body classes until you mentioned it... That made a lot of things easier. 🙂

    I got stuck at changing placeholder text on composer on specific category.
    I wrote following code into global header:

    <script>
    $(window).on('action:ajaxify.contentLoaded', function(){
     $('input.title.form-control .page-category-480').val("");
    $(".page-category-480 input[placeholder]").attr("placeholder", "This is new text");
    })
    </script> 
    

    Have I missed something or I'm just doing it completely wrong?

  • This is a bit more difficult. First, you need to use the composer loaded hook. Then, your selector needs to look for the category selector, not the page class, because the composer can load any category from any page. The input selector should look for the title class, not the placeholder property. Finally, the placeholder value needs to update when the category selector changes.

    $(window).on('action:composer.loaded', function(event, data){
      // Get the composer elements.
      var comp = $('#cmp-uuid-' + data.post_uuid);
      var catlist = comp.find('.category-list');
      var title = comp.find('input.title');
    
      if (catlist.length) { // If there's no catlist, then the post is a reply.
        var defaultPlaceholder = title.attr("placeholder");
    
        // Update the placeholder if category is 480, else set it to the default.
        function updatePlaceholder() {
          if (catlist.val() === '480') {
            title.attr("placeholder", "This is new text");
          } else {
            title.attr("placeholder", defaultPlaceholder);
          }
        }
    
        // Update placeholder each time the category changes, and once when loaded.
        catlist.change(updatePlaceholder);
        updatePlaceholder();
      }
    });
    
  • Very helpful answer. Thanks.
    When composer is first opened catlist.val() is null and placeholder is same as default. It works properly when you pick another option and change back to same one. I've modified your code a bit, but now placeholder changes on every category - because catlist.val() is always null, at least initially. I can't seem to find attribute selected on select options or any other way to check which category is selected right now. Any idea how to fix it?

    <script>
    $(window).on('action:composer.loaded', function(event, data){
      // Get the composer elements.
      var comp = $('#cmp-uuid-' + data.post_uuid);
      var catlist = comp.find('.category-list');
      var title = comp.find('input.title');
      
      if (catlist.length) { // If there's no catlist, then the post is a reply.
        var defaultPlaceholder = title.attr("placeholder");
    
        // Update the placeholder if category is 480, else set it to the default.
        function updatePlaceholder() {
          if (catlist.val() === '480' || catlist.val() === null) {
            title.attr("placeholder", "This is new placeholder");
          } else {
            title.attr("placeholder", defaultPlaceholder);
          }
        }
    
        // Update placeholder each time the category changes, and once when loaded.
        catlist.change(updatePlaceholder);
        updatePlaceholder();
      }
    });
    </script>
    
  • Strange, that script works fine on this forum. Must be an issue that is already fixed on master.

  • Ok, I'll update to latest version and get back with results. Should I first pull 1.x.x branch and then on master or can I directly pull master branch?


Suggested Topics


  • 0 Votes
    3 Posts
    179 Views

    @baris ty a lot ❤

  • 1 Votes
    13 Posts
    951 Views

    Forget it buddy. I think your reading skills a flawed. As i said before i dont have problems with my containers. The official NodeBB docker container does not adhere to essential docker rules, which are: do not mess with persistant data. But i doubt you are able to grasp that. Lets leave it here.

  • 0 Votes
    1 Posts
    382 Views

    Example here https://github.com/certbot/certbot/issues/5817

    Got the same error, never got it before, using similar basic setups. Seems very common - Does anyone have any insight in how to get around or what to check?

  • 0 Votes
    5 Posts
    2k Views

    @JaredBusch said in Is there a working SMTP/relay plugin:

    @aleksad said in Is there a working SMTP/relay plugin:

    The solution was found for this error? If there is a solution, could You share, thank you.

    Yes, I'm sorry I forgot to post I am on the road right now but I will do so later

    I did not end up using a plugin. I ended up editing /etc/postfix/main.cf myself and adding a relayhost as I happen to have one setup for other purposes.

    relayhost = 10.254.0.31
  • Issue w/ MongoLab?!?

    Technical Support
    0 Votes
    1 Posts
    645 Views

    Database running fine...until today. I have reached this delightful error - I'm not sure if MongoLab did an update and the order of authentication is now out of wack with NodeBB, but I'd love some insight. I've tried a number of re-installs and created new DB. Nothing is working.

    error: Error creating index not authorized for query on nodebb_west_sand.system.indexes
    8/8 19:09 [3002] - error: MongoError: not authorized for query on nodebb_west_sand.system.indexes
    at Function.MongoError.create (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/error.js:31:11)
    at queryCallback (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/cursor.js:171:34)
    at Callbacks.emit (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/topologies/server.js:95:3)
    at null.messageHandler (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/topologies/server.js:246:23)
    at Socket.<anonymous> (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/connection/connection.js:262:22)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)