Home Analyst Portal
Options

Apply a CSS based on a Title value

Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭

So I want to hide a tab, say 'Related Items', (maybe using CSS) if my Title on the 'General' tab contains a keyword, say 'Bananas'. Is this possible in JavaScript?

Best Answer

  • Options
    Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭
    Answer ✓

    @Geoff_Ross found two errors in the code. "indexof" should be "indexOf" and the string comparison, this.inner.Text === name should be this.inner.Text.toLowerCase() === name.toLowerCase()

    Two case errors. Once fixed, works like magic! With this concept you can literally test any field value and make any element appear or disappear. Or I'm guessing apply any any CSS style. Food for thought............. 🧐

Answers

  • Options
    Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭

    Hi @Geoff_Ross , This article by @seth_coussens put me on the right track. Here's what I have:

    function fn_HideTab(name,form){

      $('a[data-toggle=tab]').each(function(){

       if(this.innerText === name){

         $(this).hide();

       }

      });

    }


    app.custom.formTasks.add('ServiceRequest', null, function (formObj, viewModel) {

    formObj.boundReady(function () {

    if(viewModel.Title.indexof('IT Request') === -1){

    fn_HideTab("IT Request", formObj)

    }

    });

    });

    However, something isn't right. I feel like I'm on the cusp. If the Title doesn't contain "IT Request" then don't show the IT Request tab. I may come up with something more clever later, but this is PoC.

  • Options
    Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭
    Answer ✓

    @Geoff_Ross found two errors in the code. "indexof" should be "indexOf" and the string comparison, this.inner.Text === name should be this.inner.Text.toLowerCase() === name.toLowerCase()

    Two case errors. Once fixed, works like magic! With this concept you can literally test any field value and make any element appear or disappear. Or I'm guessing apply any any CSS style. Food for thought............. 🧐

  • Options
    Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭

    Ok, there's one trip-up. This all works great EXCEPT for a New SR in which case it hangs. Since there is no Title, the indexOf fails. So now I need a check for the existence of Title before I to the indexOf check.

  • Options
    Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭

    Just added a simple

    if(viewModel.Title == null) { 

    fn_HideTab("IT Request", formObj)

    } else {

    if(viewModel.Title.indexOf('IT Request') === -1) {

    ...

Sign In or Register to comment.