This content has been archived and is no longer being maintained.

Table of Contents

Article

Specialty component example: jQuery UI autocomplete email picker

This example uses the jQuery UI Selectize component. This autocomplete style component displays a list of results as you type and highlights the characters that match the search criteria.

An autocomplete email picker specialty component

An autocomplete email picker specialty component

The following code snippet is for the slider. Insert this snippet into the HTML Source area on the HTML tab of the section rule. This widget also includes specific CSS (selectize.css) and JavaScript (selectize.js) components. These are already included with the Pega 7 Platform.


<%-- Example using the SELECTIZE Jquery UI component - http://selectize.github.io/selectize.js/ --%><br />
<pega:choose><br />
<pega:when test="pxRequestor.pyPegaDesignMode= 'true'">Email Id Picker Widget</pega:when><br />
<pega:otherwise><br />
<%--Include CSSfor the widget--%><br />
<pega:static type="style" app="webwb"><br />
    <pega:file name="selectize.css"/><br />
</pega:static><br />
<%--Include JS for the widget--%><br />
<pega:static type="script" app="webwb"><br />
    <pega:file name="selectize.js"/><br />
</pega:static><br />
<%--Necessary markup for the widget. Each widget instance goes into its own obiCanvasDiv--%><br />
<select id="select-to-<pega:reference name="param.pzComponentId"/>"class="contacts" placeholder="Pick some people..."></select><br /><br />
<%--SPECIALITY CONTROL JS SUPPORT CODE BEGIN--%><br />
<%--Template - Change as necessary--%><br />
<!--<br />
Notes:<br />
1. Component Id for an instance of a speciality component can be referenced like <pega:reference name="param.pzComponentId"/><br />
   This unique id can be used to generate instance specific markup, CSS and JS. <br />
2.<br />
    /**<br />
    * To get data from Clipboard objects on loading the page    <br />
    *<br />
    * @param componentId unique component id to get data<br />
    *<br />
    * @return json object from clipboard properties<br />
    */
<br />
    pega.u.d.specialtyComponent.getClipboardData    <br />
3.<br />
    /**<br />
    * To store data back to Clipboard objects before submitting the page   <br />
    *<br />
    * @param componentId   unique component id to set data<br />
    * @param json object to submit values to clipboard properties<br />
    *<br />
    * @return void <br />
    */
<br />
    pega.u.d.specialtyComponent.setClipboardData<br />
--><br />
<script><br />
/* SpecialtyComponent requires div having id speciality_<pega:reference name="param.pzComponentId"/> in order to work properly */<br />
if(document.getElementById("select-to-<pega:reference name="param.pzComponentId"/>")){<br />
        pega.u.d.registerAsHarnessElement({<br />
        <br />
             /* onLoad function will be run on load of the page and can be use to initialize the special control with default values from clipboard properties */<br />
             onLoad : function(){<br />
                var componentId  ="<pega:reference name="param.pzComponentId"/>";<br />
                /*    Fetch data for this component from the harness container  */<br />
                var data = pega.u.d.specialtyComponent.getClipboardData(componentId);<br />
        <br />
                /*    Put in code that sets this data onto the component  */<br />
                var REGEX_EMAIL ='([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@'+<br />
                  '(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)';<br />
        $('#select-to-'+componentId).selectize({<br />
            persist:false,<br />
            maxItems:null,<br />
            valueField:'email',<br />
            labelField:'name',<br />
            searchField:['name', 'email'],<br />
            options: data.PeopleDetails,<br />
            render:{<br />
                item: function(item, escape){<br />
                    return'<div>'+<br />
                        (item.name?'<span class="name">'+ escape(item.name)+'</span>':'')+<br />
                        (item.email?'&lt;<span class="email">'+ escape(item.email)+'</span>&gt;':'')+<br />
                    '</div>';<br />
                },<br />
                option: function(item, escape){<br />
                    var label = item.name|| item.email;<br />
                    var caption = item.name? item.email:null;<br />
                    return'<div>'+<br />
                        '<span class="label">'+ escape(label)+'</span>'+<br />
                        (caption ?'<span class="caption" style="display:block">'+ escape(caption)+'</span>':'')+<br />
                    '</div>';<br />
                }<br />
            },<br />
            createFilter: function(input){<br />
                var match, regex;<br />
                // email@address.com<br />
                regex =new RegExp('^'+ REGEX_EMAIL +'$', 'i');<br />
                match = input.match(regex);<br />
                if(match)return!this.options.hasOwnProperty(match[0]);<br />
                // name <email@address.com><br />
                regex =new RegExp('^([^<]*)\<'+ REGEX_EMAIL +'\>$', 'i');<br />
                match = input.match(regex);<br />
                if(match)return!this.options.hasOwnProperty(match[2]);<br />
                returnfalse;<br />
            },<br />
            create: function(input){<br />
                if((new RegExp('^'+ REGEX_EMAIL +'$', 'i')).test(input)){<br />
                    return{email: input};<br />
                }<br />
                var match = input.match(new RegExp('^([^<]*)\<'+ REGEX_EMAIL +'\>$', 'i'));<br />
                if(match){<br />
                    return{<br />
                        email : match[2],<br />
                        name  : $.trim(match[1])<br />
                    };<br />
                }<br />
                alert('Invalid email address.');<br />
                returnfalse;<br />
            }});<br />
            },<br />
         /* onBeforeSubmit function will be run before submission of the form and can be use to submit values to clipboard properties */<br />
             onBeforeSubmit : function(){<br />
                 var componentId  ="<pega:reference name="param.pzComponentId"/>";<br />
                 /*    Put in code that fetches JSON data from the component  */<br />
                 var data ="";<br />
                 /*    Set the data for this component onto the harness container  */<br />
                 pega.u.d.specialtyComponent.setClipboardData(componentId, data);<br />
             }<br />
        },pega.u.d.getContainerSectionElement("speciality_<pega:reference name="param.pzComponentId"/>"));<br />
    }<br />
        <br />
</script><br /><br />
<%--SPECIALITY CONTROL JS SUPPORT CODE END--%><br />
</pega:otherwise>

 

Published December 6, 2016 — Updated December 9, 2016

Related Content

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.