Skip to main content

Hi All,

few questions related to K2 Five and JScript. As "green" as I'm, I coudl not fond solid answer for K25 i could replicate.

 

  • When using a JScript in Expression of a DataLabel, how do I ensure it will be fired only after the entire page contnet will be loaded ?
  • Is there no robust solution for attaching and calling a custom js file to the form/project I could use ? I found some refferences in the custom control section, but what if I have no need for custom control, and only need to call scripts ?

thx all

Petr

Hi  @Pet3Art,


 


For your questions:



  • When using a JScript in Expression of a DataLabel, how do I ensure it will be fired only after the entire page contnet will be loaded ?


 


Whether you are using a Form or View, perhaps use a Transfer Data rule for your expression once the Form or View has been initialized, that way, everything will be loaded.


 



  • Is there no robust solution for attaching and calling a custom js file to the form/project I could use ? I found some refferences in the custom control section, but what if I have no need for custom control, and only need to call scripts ?


I found this article, it may be able to help you. It is a french article though, Google Chrome should auto translate it for you :)


https://www.enk2besoin.com/2015/12/23/injecter-du-javascript-dans-un-k2-smartforms/


 


Hope this helps.


Hi Pet3Art


 


The best way to ensure that your javascript only fires after the entire formview has been loaded and rendered would be to make use of a Timer Control in the viewform. 


 


On your view or form, preform the following steps to add in a delay for when the javascript should fire.


Note: You can specify how long the delay should be by altering the interval on the timer control, keep in mind that the interval is specified in milliseconds. See the Timer Control Documentaion for more detail: https://help.k2.com/onlinehelp/k2five/userguide/5.0/default.htm#Create/K2Designer/Controls/Timer/TimerControl.htm


 


Steps: 


1) Add a Data Label and ensure that its Literal property is enabled (Checked)


2) Add a Timer control anywhere ont he viewforms design canvas.


2) On the viewforms initialize, call the Timer Start Method using the "Execute a control Method" Action Rule.


3) Set the Timer to a specified time that you have predetermined would be enough.


4) Add a new rule using "When a control on the viewform raises an event", specify that the control should point to the Timer control and the Event should be the "Ticked" event. Then add a Transfer Data rule.


6) In the transfer data rule, add your code to the data label we added in step 1


7) Save, Finish and Run the ViewForm. 


 


Result:


When the viewform is run, the timer will start which means that the timer will start counting the milliseconds that had been specified, once it reaches the amout that was spcified, the Timer Ticked event will trigger which would fire the transfer data rule inevitably firing the code contained in the transfer data rule by passing it to the data label.


 


Should you feel that this post is of use and or an accurate solution to the raised question, I kindly encourage you to mark it as such using the 'Mark as Solution', 'Kudo' andor Me Too options.


 


Kind Regards


Raymond


 


Reply