Skip to main content
Nintex Community Menu Bar

I have created custom contol like below.

 

Custom Control Code(TestCustom.cs)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//SourceCode.Forms.Controls.Web.SDK.dll, located in the GAC of the smartforms server or in the bin folder of the K2 Designer web site
using SourceCode.Forms.Controls.Web.SDK;
using SourceCode.Forms.Controls.Web.SDK.Attributes;
using System.Configuration;
using System.Net;
using System.IO;
using System.Web.UI.HtmlControls;

namespace Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl
{
 ÂControlTypeDefinition("Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl.TestCustom_Definition.xml")]

 public class TestCustom : BaseControl
 {
     private StringBuilder _htmlContent = new StringBuilder();

     public TestCustom()
     : base("div")
     {

     }

 

     protected override void OnInit(EventArgs e)
     {
            Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            base.OnInit(e);
     }

 

     protected override void OnPreRender(EventArgs e)
     {
            base.OnPreRender(e);            
            bool _designMode = base.State.Equals(SourceCode.Forms.Controls.Web.Shared.ControlState.Designtime);
            if (!_designMode)
            { 
                   _htmlContent.AppendLine("<input type='radio' name='testRadio' value='1' " + (Enabled ? "" : "diabled") + " /> Test");
            }
           else
           {
                 _htmlContent.AppendLine(" Test]");
           }

     }

 

     protected override void RenderContents(HtmlTextWriter writer)
     {
           if (_htmlContent.Length <= 0)
           {
               _htmlContent.Append("rTest]");
           }

           writer.Write(_htmlContent.ToString());

           base.RenderContents(writer);
     }

 }
}

 

Custom Control Definition(TestCustom_Definition.xml)

<?xml version="1.0" encoding="utf-8" ?>
   <ControlType>

      <Category>Display</Category>
      <Group>Mpa.Procurement.CustomControl</Group>
      <Name>TestCustom</Name>
      <DisplayName>Test Custom</DisplayName>
      <FullName>Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl.TestCustom,        Mpa.Procurement.K2.CustomSmartFormControl</FullName>
      <Properties>
          <Prop ID="IsEnabled" friendlyname="Enabled" type="bool" category="General" refreshdisplay="true" setFunction="SetControlIsEnabled">
               <Value>true</Value>
          </Prop>
          <Prop ID="IsVisible" friendlyname="Visible" type="bool" category="General" refreshdisplay="true" setFunction="SetControlIsVisible">
                <Value>true</Value>
          </Prop>
      </Properties>
    </ControlType>

 

K2 Form Designer

14821iBDFD2D2733EFBCF1.png

 

Issue

 

Disable/Hide control rules are not working for Custom Control.

 

Please help me to solve this issue.

Hi, 

Please take a look at the sample project included in the K2 Developer section located here

https://help.k2.com/onlinehelp/K2smartforms/DevRef/4.7/default.htm#Create_a_Basic_Custom_Control.html%3FTocPath%3DCustom%2520Controls%7CGetting%2520started%2520with%2520Custom%2520Controls%7C_____2

 


I found the solution for this issue.

 

Need to add the Js file to set value for enable or visible property.

 

TestCustom_Script.js

 

(function ($) {
if (typeof (Mpa) == "undefined") {
Mpa = {};
}

if (typeof (Mpa.Procurement) == "undefined") {
Mpa.Procurement = {};
}

if (typeof (Mpa.Procurement.K2) == "undefined") {
Mpa.Procurement.K2 = {};
}


if (typeof (Mpa.Procurement.K2.CustomSmartFormControl) == "undefined") {
Mpa.Procurement.K2.CustomSmartFormControl = {};
}

if (typeof (Mpa.Procurement.K2.CustomSmartFormControl.TestCustom) == "undefined") {
Mpa.Procurement.K2.CustomSmartFormControl.TestCustom = {
_getInstance: function (id) {
//alert("_getInstance(" + id + ")");
var control = jQuery('#' + id);
if (control.length == 0) {
throw 'TestCustom '' + id + '' not found';
} else {
return controlr0];
}
},

//retrieve a property for the control
getProperty: function (objInfo) {
//alert("getProperty(" + objInfo.property + ") for control " + objInfo.CurrentControlId);
if (objInfo.property.toLowerCase() == "value") {
return Mpa.Procurement.K2.CustomSmartFormControl.TestCustom.getValue(objInfo);
}
else {
return $('#' + objInfo.CurrentControlId).data(objInfo.property);
}
},


//set a property for the control. note case statement to call helper methods
setProperty: function (objInfo) {
switch (objInfo.property.toLowerCase()) {
case "isvisible":
Mpa.Procurement.K2.CustomSmartFormControl.TestCustom.setIsVisible(objInfo);
break;
case "isenabled":
Mpa.Procurement.K2.CustomSmartFormControl.TestCustom.setIsEnabled(objInfo);
break;
default:
$('#' + objInfo.CurrentControlId).data(objInfo.property).value = objInfo.Value;
}
},

//helper method to set visibility
setIsVisible: function (objInfo) {
//alert("set_isVisible: " + objInfo.Value);
value = (objInfo.Value === true || objInfo.Value == 'true');
this._isVisible = value;
var displayValue = (value === false) ? "none" : "block";
var instance = Mpa.Procurement.K2.CustomSmartFormControl.TestCustom._getInstance(objInfo.CurrentControlId);
instance.style.display = displayValue;
},

//helper method to set control "enabled" state
setIsEnabled: function (objInfo) {
alert("set_isEnabled: " + objInfo.Value);
value = (objInfo.Value === true || objInfo.Value == 'true');
this._isEnabled = value;
var instance = Mpa.Procurement.K2.CustomSmartFormControl.TestCustom._getInstance(objInfo.CurrentControlId);
instance.readOnly = !value;
},
};
}
})(jQuery);

 

Embed the Js file in Custom Control

 

passembly: WebResource("Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl.TestCustom_Script.js", "text/javascript", PerformSubstitution = true)]

namespace Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl
{
 

/ClientScript("Mpa.Procurement.K2.CustomSmartFormControl.CustomSmartFormServerControl.TestCustom_Script.js")]

 public class TestCustom : BaseControl
 {

     // Your implementation

 }

 

Include the Js methods in Definition XML

 

....

<GetPropertyMethod>Mpa.Procurement.K2.CustomSmartFormControl.TestCustom.getProperty</GetPropertyMethod>
<SetPropertyMethod>Mpa.Procurement.K2.CustomSmartFormControl.TestCustom.setProperty</SetPropertyMethod>

<Properties>
<!-- IsEnabled is used to enable/disable the control -->
<Prop ID="IsEnabled" friendlyname="Enabled" type="bool" category="General" refreshdisplay="true">
<Value>true</Value>
</Prop>

<!--IsVisible is used to show or hide the control -->
<Prop ID="IsVisible" friendlyname="Visible" type="bool" category="General" refreshdisplay="true">
<Value>true</Value>
</Prop>

</Properties>

....

 


Reply