<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>SharePoint learnings</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/asbapat/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/asbapat/feed.xml</link>
    <description>Just another Developer Network site</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:47:34 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>PnP Taxonomy Picker – Set Dynamic termset id</title>
      <link>https://docs.microsoft.com/archive/blogs/asbapat/pnp-taxonomy-picker-set-dynamic-termset-id</link>
      <pubDate>Wed, 15 Mar 2017 11:01:55 GMT</pubDate>
      <dc:creator><![CDATA[Ashwini Bapat]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/asbapat/?p=25</guid>
      <description><![CDATA[This post relates to the taxonomy picker from...]]></description>
      <content:encoded><![CDATA[This post relates to the taxonomy picker from PnP.

<a href="https://github.com/SharePoint/PnP/tree/dev/Components/Core.TaxonomyPicker">https://github.com/SharePoint/PnP/tree/dev/Components/Core.TaxonomyPicker</a>

An example of using it in your javascript and html would be as:<span style="color: black"><span style="font-family: Consolas;font-size: 9pt">
<span style="color: blue">&lt;<span style="color: maroon">input<span style="color: black"> <span style="color: red">type<span style="color: blue">="hidden"<span style="color: black"> <span style="color: red">id<span style="color: blue">="taxPickerSkill"<span style="color: black"> <span style="color: blue">/&gt;</span></span></span></span></span></span></span></span></span></span></span></span><span style="color: black;font-family: Consolas;font-size: 9pt">
</span><span style="color: black;font-family: Consolas;font-size: 9pt">
</span>

This will render a textbox and provide a SharePoint like taxonomy picker for the assigned termsetid.<span style="color: #a31515;font-family: Consolas;font-size: 9pt">
</span>

But for scenarios where the termsetid is dynamic or say you want to initialize a starting value(term) to the textbox, if you call the above function dynamically when needed, it ends up rendering a new textbox with taxonomy picker each time.

These code changes ensure that the editor textbox, button and suggestion container don't get re-added each time. If the textbox already has an associated editor, button and suggestion container, use that. The taxonomy picker can now be called dynamically to change the termsetid associated or set an initial value.

E.g:-

<span style="color: black;font-family: Consolas;font-size: 9pt"> $(<span style="color: #a31515">'#taxPickerSkill'<span style="color: black">).val("[{\"Id\":\"" + term.TermGuid + "\", \"Name\": \"" + term.Label + "\"}]");
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> initializeTaxonomyPicker();
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">OR
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">     <span style="color: blue">var<span style="color: black"> context = new SP.ClientContext.get_current();
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> $(<span style="color: #a31515">'#taxPickerSkill'<span style="color: black">).taxpicker({
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> isMulti: <span style="color: blue">false<span style="color: black">,
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> allowFillIn: <span style="color: blue">false<span style="color: black">,
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> termSetId: termSetId
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }, context);</span>

We need to make the following changes in the <span style="color: black;font-family: Consolas;font-size: 9pt">TaxonomyPicker.initialize </span>function<span style="color: black;font-family: Consolas;font-size: 9pt">.
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: green">//create a new wrapper for the control using a div<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._control = jQuery(<span style="color: #a31515">'&lt;div class="cam-taxpicker"&gt;&lt;/div&gt;'<span style="color: black">);
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: green">//detach the hidden field from the parent and append to the wrapper<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">var<span style="color: black"> parent = <span style="color: blue">this<span style="color: black">._hiddenValidated.parent();
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">if<span style="color: black"> (!parent.hasClass(<span style="color: #a31515">'cam-taxpicker'<span style="color: black">)) {
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._hiddenValidated = <span style="color: blue">this<span style="color: black">._hiddenValidated.detach();
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> parent.append(<span style="color: blue">this<span style="color: black">._control);
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">else<span style="color: black"> {
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._control = parent;
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: green">// this._initialValue = '';<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._selectedTerms = <span style="color: blue">new<span style="color: black"> Array();
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._suggestionContainer = parent.find(<span style="color: #a31515">".cam-taxpicker-suggestion-container"<span style="color: black">).length &gt; 0 ? parent.find(<span style="color: #a31515">".cam-taxpicker-suggestion-container"<span style="color: black">) : jQuery(<span style="color: #a31515">'&lt;div class="cam-taxpicker-suggestion-container"&gt;&lt;/div&gt;'<span style="color: black">);
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">if<span style="color: black"> (!<span style="color: blue">this<span style="color: black">._enterFillIn) {
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._dlgButton = parent.find(<span style="color: #a31515">".cam-taxpicker-button"<span style="color: black">).length &gt; 0 ? parent.find(<span style="color: #a31515">".cam-taxpicker-button"<span style="color: black">) : jQuery(<span style="color: #a31515">'&lt;div class="cam-taxpicker-button"&gt;&lt;/div&gt;'<span style="color: black">);
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">if<span style="color: black"> (!<span style="color: blue">this<span style="color: black">._isReadOnly) {
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._editor = parent.find(<span style="color: #a31515">".cam-taxpicker-editor"<span style="color: black">).length &gt; 0 ? parent.find(<span style="color: #a31515">".cam-taxpicker-editor"<span style="color: black">) : jQuery(<span style="color: #a31515">'&lt;div class="cam-taxpicker-editor" contenteditable="true"&gt;&lt;/div&gt;'<span style="color: black">);
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._control.empty().append(<span style="color: blue">this<span style="color: black">._editor).append(<span style="color: blue">this<span style="color: black">._dlgButton).append(<span style="color: blue">this<span style="color: black">._hiddenValidated);
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._control.after(<span style="color: blue">this<span style="color: black">._suggestionContainer);
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">else<span style="color: black"> {
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._editor = parent.find(<span style="color: #a31515">".cam-taxpicker-editor-readonly"<span style="color: black">).length &gt; 0 ? parent.find(<span style="color: #a31515">".cam-taxpicker-editor-readonly"<span style="color: black">) : jQuery(<span style="color: #a31515">'&lt;div class="cam-taxpicker-editor-readonly" contenteditable="false"&gt;&lt;/div&gt;'<span style="color: black">);
</span></span></span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._control.empty().append(<span style="color: blue">this<span style="color: black">._editor).append(<span style="color: blue">this<span style="color: black">._hiddenValidated);
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: green">//initialize value if it exists<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._editor.html(<span style="color: #a31515">''<span style="color: black">);
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">if<span style="color: black"> (<span style="color: blue">this<span style="color: black">._initialValue != undefined &amp;&amp; <span style="color: blue">this<span style="color: black">._initialValue.length &gt; 0) {
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">var<span style="color: black"> terms = JSON.parse(<span style="color: blue">this<span style="color: black">._initialValue);
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">for<span style="color: black"> (<span style="color: blue">var<span style="color: black"> i = 0; i &lt; terms.length; i++) {
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: green">//add the term to selected terms array<span style="color: black">
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">var<span style="color: black"> t = <span style="color: blue">new<span style="color: black"> Term(<span style="color: blue">null<span style="color: black">);
</span></span></span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> t.Id = terms[i].Id;
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> t.Name = terms[i].Name;
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._selectedTerms.push(t);
</span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt">
<span style="color: blue">this<span style="color: black">._editor.html(<span style="color: blue">this<span style="color: black">.selectedTermsToHtml());
</span></span></span></span></span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> }
</span>

<span style="color: black;font-family: Consolas;font-size: 9pt"> </span>]]></content:encoded>
    </item>
    <item>
      <title>Hello world!</title>
      <link>https://docs.microsoft.com/archive/blogs/asbapat/hello-world</link>
      <pubDate>Wed, 15 Mar 2017 04:08:48 GMT</pubDate>
      <dc:creator><![CDATA[BharathNalla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/asbapat/?p=1</guid>
      <description><![CDATA[Welcome to Developer Network. This is your first post. Edit or delete it, then start blogging!]]></description>
      <content:encoded><![CDATA[Welcome to <a href="https://blogs.msdn.microsoft.com/">Developer Network</a>. This is your first post. Edit or delete it, then start blogging!]]></content:encoded>
    </item>
  </channel>
</rss>