How do you validate Managed Metadata Field in a Nintex Form

  • 26 September 2014
  • 17 replies
  • 33 views

Badge +2

I have several (many) Nintex Forms with Managed Metadata Fields and I have been unsuccessful validating the fields. Problem is if left alone users can type whatever they want in the field which is not acceptable

The rules are working otherwise so far but not for Managed Metadata field, how do you validate users select from the connected field and not just type in free form text.

I have tried using the Connected field ( from the List Colum. )  and check to make sure it is not empty IsNullor Empty (Item Property Name) and that does not work.   I have also tried not(Item Property Name) - that does not work.

My question is what works?  does anyone know I need an answer ASAP.

Thanks

Carol


17 replies

Badge +11

I don't use Nintex Forms but if you can use code to do it, I found this for you:

http://prashobjp.wordpress.com/2012/01/06/validate-managed-meta-data-fields-in-item-adding-event-reciever/

Badge +2

Thank you Burkslm -  I appreciate your response, however we are now using Rules Validation a built in function in Nintex forms.  I had JavaScript codes which works originally but had to remove the JavaScript.   I will look at the information sent, but Nintex Rules validation is what I am trying to accomplish.  The JavaScript that worked previously will not work now.

Thanks

Carol

Badge +11

Yeah there are rules in InfoPath as well.

Badge +11

Would RegEx be useful?

Lisa

Badge +2

Tried   - not working for me.

Userlevel 5
Badge +9

Hi Graham,

Sorry, my answer comes a bit late...

Getting the value of a managed metadata field via the arguments of the javascript validation function is currently not supported.

To get the value of a managed metadata field, you can store its client id in a javascript variable (via the managed metadata control settings, "Advanced" section then "Client ID Javascript variable name" field), for example, "myManagedMetadataClientID" and then run the following javascript inside the javascript validation function :

function managedMetadataValidationFunction(source,arguments) {

     arguments.IsValid = true;

     // To check the number of terms populated

     if(NWF$("#" + myManagedMetadataClientID).find("span.valid-text").length != 1) {

          arguments.IsValid = false;

     }

     // To check the name of the terms populated

     var testTermPopulated = false;

     // For each term populated in the managed metadata field

     NWF$("#" + myManagedMetadataClientID).find("span.valid-text").each(function() {

          if(NWF$(this).text() == "Test term") {

               testTermPopulated = true;

          }

     });

     // If a specific term is not populated

     if(!testTermPopulated) {

          arguments.IsValid = false;

     }

}

Hope this helps

Badge +1

How do you implement this solution for multiple fields? So far when I have tried it causes all validation on the form to break.

Userlevel 5
Badge +9

Can you try with the following function ?

function managedMetadataValidationFunction(source,arguments) {

     arguments.IsValid = true;

     // To check the number of terms populated

     if(NWF$(source).parent().find("span.valid-text").length != 1) {

          arguments.IsValid = false;

     }

     // To check the name of the terms populated

     var testTermPopulated = false;

     // For each term populated in the managed metadata field

     NWF$(source).parent().find("span.valid-text").each(function() {

          if(NWF$(this).text() == "Test term") {

               testTermPopulated = true;

          }

     });

     // If a specific term is not populated

     if(!testTermPopulated) {

          arguments.IsValid = false;

     }

}

Badge +2

Caroline:  Excellent information - exactly what I am looking for with a new Nintex form!   I have been using Nintex forms and workflow for a couple years but still struggle to work properly with managed metadata fields effectively from forms or workflow....

I'm looking for some detail on how to "call" this method within the Nintex form in order to validate the MM field value:

- Is it configured as the Custom Validation function?

- Does this last version of your method still get inserted inside a validation function (as outlined by graham.williamson above) in order to call/activate it?   Or can it be called directly after placing it alone inside the "Custom Javascript" area of the Form Settings?

Any details you can give on how to setup this method for use in a Nintex form will be greatly appreciated!!

Userlevel 5
Badge +9

Hi David,

I'm glad that it can help you happy.png.

To being able to use it, you need to :

  • add the whole javascript function in the "Custom Javascript" area of the Form Settings (or in the javascript file that you can reference in the "Advanced" area of the Form settings)
  • set "Use custom validation" to "Yes" in the "Validation" area of the settings of the managed metadata field
  • set "Custom validation function" with "managedMetadataValidationFunction" in the "Validation" area of the settings of the managed metadata field

Hope this helps

Badge +5

Caroline,

I'm a bit lost on how the function works.  For each MMD field on the form do you need to add a corresponding "Client ID Javascript variable name"?    How would I modify this if I only wanted to verify that a selection was made for each MMD field?

Sorry for the questions, but Managed Metadata fields seem a bit convoluted to me.  happy.png

Regards,

Ken

Userlevel 5
Badge +9

Hi Ken,

Sorry for the delay and the confusion wink.png.

With the last javascript function that I provided in this discussion, you don't need to add each MMD client ID in a javascript variable. It's a better version than the first javascript function I shared wink.png.

You just need to reference the javascript function in the form settings and edit the control settings of each MMD field to set  "Use custom validation" to "Yes" and "Custom validation function" with "managedMetadataValidationFunction" and that's all happy.png.

Tell me if it's not clear wink.png

Badge +5

Ah...now I get it!  Thank you for clearing that up for me.

Ken

Userlevel 5
Badge +9

Perfect ! I'm glad I could help happy.png

Badge +5

Caroline,

I've finally gotten around to working with your validation code.  It works...somewhat.  For some reason it produces a validation error regardless if the field is populated or not.  If I enter a new value and save/submit, the error persists.

We are using a document library with checkout/check-in and versioning enabled (if it makes any difference).

Any ideas why it would behave in this manner?

Ken  

Here is what I have in the Custom Javascript:

function managedMetadataValidationFunction(source, arguments) {
    arguments.IsValid = true;    // To check the number of terms populated
    if (NWF$(source).parent().find("span.valid-text").length != 1) {
        arguments.IsValid = false;
    }
    // To check the name of the terms populated    
    var testTermPopulated = false;
    // For each term populated in the managed metadata field
    NWF$(source).parent().find("span.valid-text").each(function() {
        if (NWF$(this).text() == "Test term") {
            testTermPopulated = true;
        }
    });    // If a specific term is not populated    
    if (!testTermPopulated) {
        arguments.IsValid = false;
    }
    //alert(testTermPopulated);
};
Badge +5

Since we only needed to test for an empty value, we alter the script (see below) and now it works as needed.

function managedMetadataValidationFunction(source, arguments) {
arguments.IsValid = true;
if (NWF$(source).parent().find("span.valid-text").length != 1) {
arguments.IsValid = false;
}
};

Thank you!

Userlevel 5
Badge +9

Hi Ken,

Yes that's correct. The previous script you posted was to check if the managed metadata field had a term which label is "Test term" and not only if a term was populated or not.

Thanks for your feeback happy.png

Reply