cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Form rules for hyperlink field

Are there Forms rules which allow rule-making against the web address and text to display elements of a hyperlink field?

It would appear from where I am sitting that rule-making against the two different parts of a hyperlink field is not currently supported by Nintex Forms, correct?

0 Kudos
Reply
3 Replies
Workflow Hero

Re: Form rules for hyperlink field

Can you give an example of what you're trying to accomplish?




SharePoint 2013 On-Prem | Nintex Forms & Workflow Enterprise
0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Form rules for hyperlink field

One thing that is being requested from some technical reviewers is to have an error thrown when someone inputs a value for Display Text and not for URL.  The impact of doing this right now is for no hyperlink value to be created, as if nothing had been entered and no warning is thrown that this will be the case.  So, a validation rule which targets the URL component of the hyperlink like __not(startsWith(URL,"http")__ .  That being said, wondering if there is a background rule intrinsic to Nintex Forms running on SharePoint which is smart about the format of the Hyperlink field would be good, so that any attempt to mis-configure a hyperlink field throws a warning/error without any rule application would be useful, but it might run afoul of non-standard ways of working and be a problem for a subset of users.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Form rules for hyperlink field

You're correct. You will not be able to use a native rule; however, you should be able to use a rule with a little JavaScript.

Go to Settings -> Custom JavaScript and paste in the following code:

function checkLink() {
     var link = NWF$("input[id$='Description']").prop('value');
     if (link.startsWith('http')) return true;
     return false;
}‍‍‍‍‍‍‍‍‍‍

Next, create a validation rule on your Hyperlink field and simply enter checkLink() into the condition field, like this:

Enter the message of your choice.

Let me know if you have any trouble with that.


Update:

I decided to take this a step further and make it more dynamic so others could use it as well.

I've created two functions:

  1. hyperlinkMustNotStartWith
  2. hyperlinkMustNotContain

Each of these functions accepts a string value, which can be passed from the rule. This means you can test for a text value that the Description field starts with OR contains.

function hyperlinkMustNotStartWith(value) {
     var link = NWF$("input[id$='Description']").prop('value');
     if (link.startsWith(value)) return true;
     return false;
}

function hyperlinkMustNotContain(value) {
     var link = NWF$("input[id$='Description']").prop('value');
     if (link.includes(value)) return true;
     return false;
}

You can choose to use either or both of the functions if you'd like. 

Here's how they're called ( || means OR ):

Note:

This will currently only work for one hyperlink control on the form.

I'll have to look into adding in the ability to pass through a class or maybe Client ID JavaScript Variable in the future.




SharePoint 2013 On-Prem | Nintex Forms & Workflow Enterprise
0 Kudos
Accept as Solution Reply