Page 1 of 2

Managed Metadata

Posted: 25 Feb 2014
by stieland
I am trying to work with Managed Metadata fields and have not been able to pick up the change event for a Managed Metadata field.

fd.field('RCategory').change(function() {
alert('Category Changed');
});

Never fires the alert. Do Managed Metadata fields work differently?

Re: Managed Metadata

Posted: 26 Feb 2014
by Dmitry Kozlov
Please, try to use the following code to handle changing of Management Metadata field:

Code: Select all

var container = fd.field('InternalName').control()._el().find('.ms-taxonomy').get(0);
container.JavascriptOnValidation = "alert('Managed metadata changed!')"; 

Re: Managed Metadata

Posted: 26 Feb 2014
by stieland
While that is firing when the item is updated, also a few more times. I am still missing a few items to get my piece working.

I need to know when the managed metadata field equals 'Option 2' and if it equals 'Option 2', then I need to make another control visible. If it does not equal 'Options 2' then the other control is hidden.

I do not seem to be able to get the value of the managed metadata field so that I can compare it.

Re: Managed Metadata

Posted: 27 Feb 2014
by Dmitry Kozlov
You can find examples of getting and setting Taxonomy field values in the following article:

http://blog.vgrem.com/tag/taxonomywebtaggingcontrol/

Getting:

Code: Select all

var container = fd.field('InternalName').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();

Re: Managed Metadata

Posted: 03 Feb 2015
by Christian Heinrich
Should that alternat event registration also work for SP 2010?

I did put that code into the JavaScript part of the form, but the alert never shows up...

Re: Managed Metadata

Posted: 04 Feb 2015
by Dmitry Kozlov
Please, try the following code for SP2010:

Code: Select all

var container = fd.field('TermStore1').control()._el().find('div.ms-taxonomy').get(0);
container.JavascriptOnValidation = "alert('Managed metadata changed!')"; 

Re: Managed Metadata

Posted: 10 Aug 2015
by Dan
It seems like the only thing you can do in here is report out that it's fired. Trying to call an handler function doesn't seem to work properly. I've tried a couple things and some variations of them:


container.JavascriptOnValidation = "mmChangeHandler()";


function mmChangeHandler() {

console.log("Managed Metadata Changed!");

}

/* OR */

container.JavascriptOnValidation = function() {

console.log("Managed Metadata Changed!");

}

Re: Managed Metadata

Posted: 11 Aug 2015
by rostislav
You can define a global function and then call it:

container.JavascriptOnValidation = "func()";

Code: Select all

window.func = function () { 
   console.log("Managed Metadata Changed!");
}

Re: Managed Metadata

Posted: 12 Aug 2015
by Dan
That worked! Thanks!

Re: Managed Metadata

Posted: 05 Oct 2016
by Katy
Hi!

I checked with alert and it works fine indeed. I need to insert the check for mandatory field with metadata. I tried some options like:

fd.field('FieldName').control()._el().find('.ms-taxonomy').value()

fd.field('FieldName').control()._el().find('.ms-taxonomy').value() == ""

fd.field('FieldName').control()._el().find('.ms-taxonomy').length > 0

but nothing works :-( Howcan I use it in IF statement to check if the metadata field contains any information?