Determine if a K2 view/form is a subview or subform

  • 19 February 2015
  • 4 replies
  • 8 views

Badge +10

Hi All,

 

Is it possible to determine if a view or form has been opened as a subview or subform?

I can do it passing in some parameter which I can then set when actually opening it as a subview or subform, but it would make the view/form more independent if this information can be determined somehow without the caller having to supply a value.

I've had a look through all the system variables but it does not seem like any of those will give an indication.

 

Any ideas would be welcomed!

 

Regards,

JohanL


4 replies

Badge +10

If I have understood the question correctly. In smartforms, I dont think it's possible to open a  form as a subview and vice versa. SO a form would always be called as a subform and a view would always be called as a subview. 

Badge +10

Hi,

 

Yes you cannot open a form as a subview, and visa versa.

However, you can open a form as a subform from either a view or form using the Open a subform action and also so for a view using the Open a subview action.

What will happen during runtime is that the form or view will be rendered as a popup.

 

My question relates to how I can find out if the form/view is displaying as a popup or not.

 

Regards,

JohanL

Userlevel 1
Badge +8

Hi Johan

 

I think you can achieve what you require with some JavaScript. I'm certainly no expert, but the following seems to work for me.

 

1. Create a view and drop 2 labels on it.  Call one "Script Data Label" and the other "Value Data Label"

2. Add the following Javascript as an expression to "Script Data Label"

 

<script type="text/javascript">$(document).ready (function() { document.getElementsByName("Value Data Label")[0].innerHTML = (window.opener==null)});</script>

 

3. Create a form and add a button to open the view as a subview

4. Test opening both the view directly and via the form

5. "Value Data Label" text will be set to true when you open the subview via the form, and false when you open the view directly (Perversely in my opinion - I would have expected the reverse result, but then again I'm no Javascript expert)


There is probably a better way of targeting the Data label (by title for example) but  you get the idea.

Badge +10

Hi Andrew,

 

This is very clever and works well!

 

Thanks for the tip.

 

Regards,

JohanL

Reply