Add "User Fields" support for "Field Type" - TAG


(Stav Sitnikov) #1

hi is it possible to add an option for the “User Fields” that the input is Tags ?

Thanks .


(Jeff Atwood) #2

Hmm, I don’t think so but I wonder if this fits into any of the work @neil is doing…?


(Neil Lalonde) #3

Adding tags to a person’s profile is something on my to-do list in the near future. @stav_sitnikov Can you explain your use case?


(Stav Sitnikov) #4

I would like users to add Personal Skills to their Profile using tags .

Thanks .


(Ellen Badgley) #5

Chiming in very late to this, but I’m recording it here in case it helps someone else: I had the same question and I found that it was very straightforward to implement a custom user field with a tag chooser interface. The reason is that tag lists are stored as text, so you can use a text-based user custom field (you will simply end up with a comma-separated list of tags).

The short solution is as follows:

  1. Make a custom plugin (I used @Falco’s discourse-signatures as a model)
  2. In your plugin.rb, declare your custom user field of type “text”
  3. In your connector hbs, create a div with class tag-controls and hook it up to your custom field (in my case model.custom_fields.custom_view_tags as follows)
   <div class="controls tag-controls">
            <label>Custom View Tags</label>
            {{tag-chooser tags=model.custom_fields.custom_view_tags blacklist=selectedTags allowCreate=false placeholder="" everyTag="true" unlimitedTagCount="true"}}
          </div>
          <div class="instructions">All selected tags will be shown on the custom view page.</div>```

I'm trying to implement a custom header-pill that will give the user the ability to jump to a search for selected tags, and the above has worked nicely for me in getting the custom user preference item the way I want it.

(Ellen Badgley) #6

An update: I did run into some wrinkles in the case where I only had one tag selected in the new tag-chooser. The issue is that if only one tag is selected, it is stored as straight text and then line 14 of assets/javascripts/discourse/components/tag-chooser.js.es6 fails because tags.join() is meaningless for a string.

I got around this in a less-than-elegant way (which I may improve upon later) by copying the tag-chooser component and creating my own custom version that will check if tags is simply a string and handle it appropriately. So the code I posted above would now be:

{{mitre-tag-chooser tags=model.custom_fields.custom_view_tags blacklist=selectedTags allowCreate=false placeholder="" everyTag="true" unlimitedTagCount="true"}}

where mitre-tag-chooser is my custom version.