URL creation: Client script

lomouhamadou
Kilo Guru

Hi all,

I need your help once again.

I have this client script on HR case that check if an URL is added in the additional comment. If yes, then create the hyperlink.

However when the link is "www.google.be" then cae is submitted but link is string and when the url contains "http(s)" then client script give an error.

Any idea to help on this ?

function onSubmit() {

      // check comments and add href

      var new_comments = g_form.getValue('comments')+'';

      if(new_comments!=''){

              g_form.setValue('comments', urlify(new_comments));

      }

      // check notes and add href

      var new_notes = g_form.getValue('work_notes')+'';

      if(new_notes!=''){

              g_form.setValue('work_notes', urlify(new_notes));

             

      }

}

// function to create link

function urlify(text) {

      var urlRegex = /(https?:\/\/[^\s]+)/g;

      return text.replace(urlRegex, function(url) {

              alert($_URI);

              return '[code]<p><a class="web" target="_blank" href="' + url + '">' + url + '</a></p>[/code]';

      });

}

1 ACCEPTED SOLUTION

well, there is only one place where you use the URI... the alert. I assume the alert is there only for debug purposes. What happens if you remove/comment that line?



The $-notation seems to be some jQuery syntax which would trigger a best practice violation as well. You should work with g_form.getValue / g_form.getDisplayValue instead.


View solution in original post

5 REPLIES 5

lomouhamadou
Kilo Guru

I commented the alert