Forum Discussion

allensmith81's avatar
13 years ago

RestAPI & Tags

Hi,


we have a developer forum where the developers could be using a Java wrapper, C++ Wrapper or a Python Wrapper. I am wanting to develop an component which will ask the user on first post which wrapper they are using and attach it to that post.

 

My questions:

 

What sort of syntax does the rest api need to post new tags to a message upon creation of the post?

 

how could I prevent the user posting the post unless they have selected a valid option from the drop down?

1 Reply

  • We do a lot of such stuff in our community.  Here is an exaple that works for us to enforce the subject has enough "meat" to it and adds a tag if the subject contains a certain pattern.  This can be adapted to check a pull down instead of the subject.

     

    <@liaAddScript>
    ;(function ($) {
        $('.lia-button-Submit-action').bind('click', function() {
            var tag_field = document.getElementById("lia-tags");
            var subject_field = document.getElementById("lia-subject");
            if (subject_field.value == "CASE: 6XXXXXXXX: Device is experiencing high CPU") {
                subject_field.value = "";
            } else if (subject_field.value.match(/^CASE:\s+6[0-9]{8}\s*:?\s*$/)) {
                alert("Please specify an additional summary in the Subject.");
                subject_field.focus();
                return false;
            } else if (subject_field.value.match(/.*6[0-9]{8}\b.*/)) {
                var srnum = subject_field.value.match(/.*(6[0-9]{8})\b.*/)[1];
                var tags = tag_field.value;
                var tagsre = new RegExp(".*\btz:link:" + srnum + "\b.*");
                if (!tags.match(tagsre)) {
                    if (tags == '') {
                        tag_field.value = 'tz:link:' + srnum;
                    } else {
                       tag_field.value = tags + ',tz:link:' + srnum;
                    }
                }
            }
            subject_field.focus();
        });
    })(LITHIUM.jQuery);    
    </@liaAddScript>

     

    This does a few things.  First, it checks the subject field to see if it matches a pattern corresponding to one of our case IDs.  If so, a custom tag is applied in the format of "tz:link:CASE_NUMBER".  If the only thing in the subject is a case number, then it forces the user to enter an additional title.  All of this logic is bound to the submit button using jQuery.

     

    Note: we don't use the REST API here since the topic hasn't been started yet.  We don't have a thread or message ID.  However, we can inject tags on post.