{"id":2415,"date":"2017-09-13T16:07:49","date_gmt":"2017-09-13T14:07:49","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=2415"},"modified":"2017-11-24T17:01:41","modified_gmt":"2017-11-24T16:01:41","slug":"spfx-field-customizer-extension-blur-field","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/spfx-field-customizer-extension-blur-field\/","title":{"rendered":"SPFx Field Customizer Extension &#8211; blur field"},"content":{"rendered":"<p>To extend the SharePoint user experience with modern pages en libraries the SharePoint Framework Extensions can be used. Currently three new extension types are available:<\/p>\n<ol>\n<li>ApplicationCustomizers &#8211; Adds scripts to the page, as well as access well-known HTML element placeholders and extend them with custom renderings.<\/li>\n<li>FieldCustomizers &#8211; Provides modified views to data for fields within a list.<\/li>\n<li>CommandSets &#8211; Extends the SharePoint command surfaces to add new actions, and provides client-side code that you can use to implement behaviors.<\/li>\n<\/ol>\n<blockquote><p>&#8220;<a href=\"https:\/\/dev.office.com\/blogs\/sharepoint-framework-extensions-rc0-now-available\">SharePoint Framework Extensions RC0 now available<\/a>&#8220;<\/p><\/blockquote>\n<p>Recently I tried to create a very simple field customizer extension where contents of a field can be blurred. This is like the example shown in the Build 2017 video &#8216;<a href=\"https:\/\/channel9.msdn.com\/Events\/Build\/2017\/B8032\">Create the modern workplace with the SharePoint Framework<\/a>&#8216;, only <i>much<\/i>, <i>much<\/i> simpler!<\/p>\n<p>The result can look like the figure below.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/1-Field-Extension-blur-blurred-field-value.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2424\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/1-Field-Extension-blur-blurred-field-value.png\" alt=\"1-field-extension-blur-blurred-field-value\" width=\"547\" height=\"229\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/1-Field-Extension-blur-blurred-field-value.png 547w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/1-Field-Extension-blur-blurred-field-value-300x126.png 300w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/a><\/p>\n<p>Figure 1 &#8211; Blurred field value<\/p>\n<p>When hovering over the content of the field is shown.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/2-Field-Extension-blur-hover-field-value.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2423\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/2-Field-Extension-blur-hover-field-value.png\" alt=\"2-field-extension-blur-hover-field-value\" width=\"546\" height=\"230\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/2-Field-Extension-blur-hover-field-value.png 546w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/2-Field-Extension-blur-hover-field-value-300x126.png 300w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/a><\/p>\n<p>Figure 2 &#8211; At hover the field value is shown<\/p>\n<p>The blur is set to a random field here. The functionality has probably more value to a field (not) showing a social security number or a phone number.<\/p>\n<p>To implement this functionality three things has to be done:<\/p>\n<ol>\n<li>Generate a field customizer extension project from the latest SharePoint Framework Yeoman generator.<\/li>\n<li>Blur the field value and show the value at hover. This is done purely in css.<\/li>\n<li>Adjust the onRenderCell function to implement the blur on the field value and show the value on hover.<\/li>\n<\/ol>\n<h4>Generate a field customizer extension<\/h4>\n<p>There is extensive <a href=\"https:\/\/dev.office.com\/sharepoint\/docs\/spfx\/extensions\/get-started\/building-simple-field-customizer\">documentation<\/a> available on how to create an extension project, coding the field customizer and debugging the field customizer using gulp serve and query string parameters. To avoid duplicate content please read that documentation and come back here to proceed.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2422\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings.png\" alt=\"3-field-extension-blur-project-settings\" width=\"840\" height=\"257\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings.png 840w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings-300x92.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings-768x235.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/3-Field-Extension-blur-project-settings-600x184.png 600w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><br \/>\n<\/a>Figure 3 &#8211; Settings used to generate a field customizer extension<\/p>\n<p>Test the field customizer without making any changes by using &#8216;gulp serve&#8217; and adding<br \/>\n<em>?loadSPFX=true&amp;debugManifestsFile=https:\/\/localhost:4321\/temp\/manifests.js&amp;fieldCustomizers={&#8220;Status&#8221;:{&#8220;id&#8221;:&#8221;365c26e5-f431-4145-a322-dddc9c94c367&#8243;}}<\/em><br \/>\nTo your SharePoint list url, where specific items for this project are displayed in the last part:<\/p>\n<p><strong>fieldCustomizers={&#8220;Status&#8221;:{&#8220;id&#8221;:&#8221;365c26e5-f431-4145-a322-dddc9c94c367&#8243;}}<\/strong><\/p>\n<p><strong>Id<\/strong> is the guid of the field customizer extension associated with this field and can be found in the customizer&#8217;s manifest file.<\/p>\n<p><strong>Status<\/strong> is the internal field name which should have its rendering controlled by the field customizer. Using the &#8216;TestFieldCustomizer&#8217; list shown above you can easily use the &#8216;<strong>Percent<\/strong>&#8216; column to have its rendering controlled by the field customizer, it doesn&#8217;t really matter.<\/p>\n<p><strong>Note<\/strong>: when using the Title column the field value is set to &#8216;undefined&#8217;, because this field is &#8216;linked to item with edit menu&#8217; and the html is slightly different for that. When another field of type Single line of text is added, the rendering is as expected using the field customizer.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/4-Field-Extension-blur-field-value-undefined.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2421\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/4-Field-Extension-blur-field-value-undefined.png\" alt=\"4-field-extension-blur-field-value-undefined\" width=\"548\" height=\"235\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/4-Field-Extension-blur-field-value-undefined.png 548w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/4-Field-Extension-blur-field-value-undefined-300x129.png 300w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/a><\/p>\n<p>Figure 4 &#8211; field values set to &#8216;undefined&#8217;<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/5-Field-Extension-blur-field-value-single-line-of-text.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2426\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/5-Field-Extension-blur-field-value-single-line-of-text.png\" alt=\"5-field-extension-blur-field-value-single-line-of-text\" width=\"639\" height=\"223\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/5-Field-Extension-blur-field-value-single-line-of-text.png 639w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/5-Field-Extension-blur-field-value-single-line-of-text-300x105.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/5-Field-Extension-blur-field-value-single-line-of-text-600x209.png 600w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/a><\/p>\n<p>Figure 5 &#8211; Field type &#8216;Single line of text&#8217;<\/p>\n<p>Blur the field value and show the value at hover<\/p>\n<p>To standard blur the field value and show it at hover, this is what is needed in HelloWorldFieldCustomizer.module.scss:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n.HelloWorld {\r\n\r\n .blurredCell {\r\n\r\n  background-color: '#e5e5e5';\r\n\r\n  display: 'inline-block';\r\n\r\n  filter:blur(2.5px);\r\n\r\n  margin-left: 3px;\r\n\r\n }\r\n\r\n .blurredCell:hover {\r\n\r\n  filter:none;\r\n\r\n }\r\n\r\n}\r\n\r\n<\/pre>\n<h4>Adjust the onRenderCell function<\/h4>\n<p>To actually implement the functionality the onRenderCell function has to look like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@override\r\npublic onRenderCell(event: IFieldCustomizerCellEventParameters): void {\r\n  event.domElement.classList.add(styles.HelloWorld);\r\n  event.domElement.innerHTML = `\r\n    &lt;div class='${styles.blurredCell}'&gt;\r\n     ${event.fieldValue} &lt;\/div&gt;\r\n    `; \r\n}\r\n<\/pre>\n<p>Where styles.HelloWorld, the root, is applied, whereas .blurredCell is the standard class at a field value. The hover action sets the filter to none, what makes the field value visible to the user.<\/p>\n<p>Playing with the debug url can render this at a different field:<\/p>\n<p>?loadSPFX=true&amp;debugManifestsFile=https:\/\/localhost:4321\/temp\/manifests.js&amp;fieldCustomizers={&#8220;<strong>Percent<\/strong>&#8220;:{&#8220;id&#8221;:&#8221;365c26e5-f431-4145-a322-dddc9c94c367&#8243;}}<\/p>\n<p>This will look like figure 1 and 2, or<\/p>\n<p>?loadSPFX=true&amp;debugManifestsFile=https:\/\/localhost:4321\/temp\/manifests.js&amp;fieldCustomizers={&#8220;<strong>LikeTitle<\/strong>&#8220;:{&#8220;id&#8221;:&#8221;365c26e5-f431-4145-a322-dddc9c94c367&#8243;}}<\/p>\n<p>That looks like figure 6.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2449\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension.png\" alt=\"6-field-extension-blur-implemented-blur-field-customizer-extension\" width=\"832\" height=\"410\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension.png 832w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension-300x148.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension-768x378.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/09\/6-Field-Extension-blur-implemented-blur-field-customizer-extension-600x296.png 600w\" sizes=\"auto, (max-width: 832px) 100vw, 832px\" \/><\/a><br \/>\nFigure 6 &#8211; Implemented blur field customizer extension<\/p>\n<h4>Summary<\/h4>\n<p>This post showed a really simple example on how to implement a field customizer extension.<br \/>\nFor now it only works in read mode in a list view, not in the details pane of an item, nor in the DispForm.<\/p>\n<h3>There is a catch<\/h3>\n<p>Sometimes when navigating away from the debug url, eg navigating to \/Lists\/TestFieldCustomizer\/AllItems.aspx in this example, the &#8216;Allow debug scripts?&#8217; screen is still shown. This will happen because there are references to debug files and cookies which can be removed by adding<\/p>\n<p><b>?reset=true<\/b><\/p>\n<p>to the url for just one time. Then all references are cleanup and you&#8217;re good to go.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To extend the SharePoint user experience with modern pages en libraries the SharePoint Framework Extensions can be used. Currently three new extension types are available: ApplicationCustomizers &#8211; Adds scripts to the page, as well as access well-known HTML element placeholders &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/spfx-field-customizer-extension-blur-field\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,41],"tags":[37,48],"class_list":["post-2415","post","type-post","status-publish","format-standard","hentry","category-office-365","category-sharepoint","tag-office365","tag-spfx"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=2415"}],"version-history":[{"count":27,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2415\/revisions"}],"predecessor-version":[{"id":2486,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2415\/revisions\/2486"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=2415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=2415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=2415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}