K2 custom controls and javascript

  • 30 May 2017
  • 1 reply
  • 18 views

Badge +7

Hi There,

 

 

 

 

I've just started with k2 custom controls today using the articles supplied on help.k2.

 

 

 

 

 

I have a javascript array which is driven by on click events in the UI. It is basiclaly a row of html buttons that change state when toggled, unerneath this is an array in which correrspding elements are also toglled between "0" and "1".

 

 

 

 

 

I was intending to store the array.toString() inside the custom control as text.

 

 

 

 

 

I have sucessfully implemented the requried javascript and deployed to the server. However I have no idea how to get the array value into and out of k2.

 

 

 

 

 

Best guess was to use get set as defined below but I am confused:

 

 

 

 

 

var weeks = ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0","0","0","0"];

 

 

 

 

 

(function ($, undefined)
{
      if (typeof CustomCOntrols === "undefined" || CustomControls === nul) CustomControls  = {};

       CustomControls.Textbox =
       {     
              getValue: function (objInfo)
              {
                    return $( "#"+ objInfo.CurrentControlID).val();
              },

              setValue: function (objInfo)
              {
                     $("#" + objInof.CurrentControlID).val(ObjInfo.Value);
              }
       },
}
(jQuery)); 

 

 

 

 

 

so my question is two parts:

 

 

 

 

 

a) am I on the right track ?

 

 

b) what do I need to change in the code above to set the value of the array? 

 

 

 

 

 

For me I would have though it would something like:

 

 

 

 

 

 

 

 

setValue: function (weeks)
              {
                     $("#" + weeks.CurrentControlID).val(weeks.toString());
              }

 

 

 

 

 

but I dont the importance of the var ObjInfo, is this a reserved k2 thing?

 

 

 

 

 

also when I pull this out again I would need to repopulate the array but no idea how to do that!!.

 

 

 

 

 

 getValue: function (objInfo)
              {
                    return $( "#"+ objInfo.CurrentControlID).val();
              },

 

 

 

 

 

Thanks in advance....

 


1 reply

Badge +7

Ok so short answer is you can't do it that way, as with all k2 things you must first have a smartobject with some data in it to start manipulating the functions. SO I have setup a SMO and used the VSextensions for K2 Items to rebuild this project. when the getValue function is called and there is data in the control provided by calling a smart object method on the initialize view method, these funtions fire. At this point I am breaking out to call other functions that allow me to work with my JSarray weeks.

Reply