Topic
  • 4 replies
  • Latest Post - ‏2012-10-10T17:44:21Z by LaszloKertesz
LaszloKertesz
LaszloKertesz
15 Posts

Pinned topic How to access coach view values within a HTML code?

‏2012-10-04T12:41:14Z |
Hi there,

We need to access the values of coach views within a Custom HTML view of a coach, but don't know how to do that. Unfortunately dojo.byId and dijit.byId does not returns the coach view by its Control Id general property.

For example when we have two Text view on the coach with Control Ids "Text1" and "Text2" and a Custom HTML view, how could we get their values in the JavaScript code written into the Custom HTML view?

Thanks in advance,
Leslie
Updated on 2012-10-10T17:44:21Z at 2012-10-10T17:44:21Z by LaszloKertesz
  • kolban
    kolban
    3322 Posts

    Re: How to access coach view values within a HTML code?

    ‏2012-10-04T13:47:14Z  
    Hi Leslie,
    I had a similar question before and after some discussions with folks I was led to believe that this is not the right thinking.

    If you have custom HTML in your Coach that contains JavaScript that tries to access the variables of other Coach Views directly, the argument is that you are binding that code too tightly. One solution would be to create a new Coach View as opposed to Custom HTML. A Coach View can have custom html in it as well as bind to variables.

    So .. imagine you have a Text Coach View bound to variable "XYZ". You now want some custom HTML that can also access XYZ and be told when it changes. If you create a new Coach View definition that contains HTML as well as a binding to XYZ then we will have achieved what you want.

    If I may ask, what is it that you want to place into your Custom HTML in your specific instance? What is it (functionally) that your desired Custom HTML is going to do?

    Neil
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to access coach view values within a HTML code?

    ‏2012-10-04T14:26:50Z  
    • kolban
    • ‏2012-10-04T13:47:14Z
    Hi Leslie,
    I had a similar question before and after some discussions with folks I was led to believe that this is not the right thinking.

    If you have custom HTML in your Coach that contains JavaScript that tries to access the variables of other Coach Views directly, the argument is that you are binding that code too tightly. One solution would be to create a new Coach View as opposed to Custom HTML. A Coach View can have custom html in it as well as bind to variables.

    So .. imagine you have a Text Coach View bound to variable "XYZ". You now want some custom HTML that can also access XYZ and be told when it changes. If you create a new Coach View definition that contains HTML as well as a binding to XYZ then we will have achieved what you want.

    If I may ask, what is it that you want to place into your Custom HTML in your specific instance? What is it (functionally) that your desired Custom HTML is going to do?

    Neil
    I think there are 2 scenarios (at least) -
    One is accessing coach view values from JS within a custom html tag all within the SAME coach view. An example being, if a coach view is bound to a variable then from within a custom html tag how can you access the bound variable? To access it from within one of the standard events (load, view.. ) you would use 'this.context.binding.get("value")' because the 'this' is the coach view object in these events.

    The second scenario is what I believe Neil is addressing - accessing elements of one view coach from another. I would agree that in this scenario the right approach would be to either create the single coach view or work in a subscribe/consume event model pattern depending on the use case.
  • LaszloKertesz
    LaszloKertesz
    15 Posts

    Re: How to access coach view values within a HTML code?

    ‏2012-10-04T14:41:35Z  
    We don't want to make new coach views for all our forms where we need to check the relationships between the control values, just want to make one function that checks the validity of the entire form and prevent the post to the server and displays the error message in an alert window when there is any error.

    For now we have the solution - we can call our function with an array that contains the Control Id and value for all the widgets on the form.

    I think, this is the third way...

    Anyway, thank you all for your replies!
    Leslie
  • LaszloKertesz
    LaszloKertesz
    15 Posts

    Re: How to access coach view values within a HTML code?

    ‏2012-10-10T17:44:21Z  
    Ok, finally we decided to use an outer coach view and access control data through that.
    Thanks Neil, you're right, this is the best solution.

    Leslie