This content has been archived.

Table of Contents

Specialty component example: jQuery slider in a text input

In the following example, there are two inputs – a slider and a number input. The slider is a jQuery slider that you can use to set an amount. You can use a slider to enter a numerical value, for instance to set a price or set an interest rate percentage in a loan calculator. The number input is a text input control that is tied to the same property as the slider. Values set by using the slider are reflected on the input, and values set by using the text input are also reflected on the slider.

The slider created by using specialty components

The JQuery slider that you can create as a specialty component

The slider specialty component also defines parameter values that can be passed in where the component is used.

The slider specialty component parameters

The slider specialty component parameters

To use the slider specialty component in your UI, drop in a section include and set the Section name to the slider that you created. Next, provide parameter values and specify any additional presentation-related configuration. If the property is bound to the control by passing in the value to the Value parameter, the slider is bound to .Amount. In addition, the slider has a minimum value and a maximum value.

The General tab of the section include cell properties

 

The cell properties Parameters tab of a section include.

The following code snippet is for the slider. Insert this snippet into the HTML Source area on the HTML tab of the section rule.

<pega:choose><br />
<%-- Set what the code looks like at design time --%><br />
<pega:when test="pxRequestor.pyPegaDesignMode= 'true'">Slider Widget</pega:when><br />
<pega:otherwise><br />
 <br />
<%--<br />
A "Pega-aware" JQuery UI slider control<br />
This control can work in conjunction with a Pega input control, such that when bound to the same property changing the value in the Pega control will update the slider, and vice-versa. --%><br />
 <br />
<%--No CSS and JS include for this example as Pega UI comes in with JQuery UI library by default--%><br />
 <br />
<%--JS support code--%><br />
<script><br />
     var getPropHandleBoundToWidget = function(componentId) {<br />
          var entryHandlesObj = window['pzEntryHandles_' + componentId];<br />
          var widgetProp = entryHandlesObj["Value"];<br />
          return pega.u.property.toHandle(widgetProp);<br />
     }<br />
</script><br />
 <br />
<%--<br />
Append the specialty component id as there can be many sliders on the page<br />
--%><br />
<div id='slider_<pega:reference name="param.pzComponentId"/>'></div><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 />
 <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 />
 <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 />
 <br />
<script><br />
 <br />
/* SpecialtyComponent requires div having id speciality_<pega:reference name="param.pzComponentId"/> */<br />
 <br />
if(document.getElementById("speciality_<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 />
                        Return if the component is already rendered  */
<br />
                   if(document.getElementById("slider_" + componentId).hasChildNodes()) {<br />
                        return;<br />
                   }<br />
 <br />
                   var textInput = $('[name="' + getPropHandleBoundToWidget(componentId) +'"]');<br />
 <br />
                   // Initialize the slider<br />
                   $("#slider_" + componentId).slider({<br />
                        range: "min",<br />
                        value: parseInt(data.Value),<br />
                        min: parseInt(data.MinValue),<br />
                        max: parseInt(data.MaxValue),<br />
                        slide: function( event, ui ) {<br />
                             textInput.val(ui.value);<br />
                        }<br />
                });<br />
                    /* Add an on-change event listener to update the widget if data in the text input is updated */<br />
                   textInput.change(function() {<br />
                        $("#slider_" + componentId).slider("value", textInput.val());<br />
                   });<br />
                  <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><br />
</pega:choose>
Suggest Edit

50% found this useful


Related Content

Have a question? Get answers now.

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