1. JSFormJavaScript

    Article: AN0001715Updated: 09.11.2018

    Object for work with javascript in the form.

    Object properties 

    Name Description
    void Add(string key, string script) Function adds a script block into a page. The script itself does not have go be wrapped in tags.
    void AddStartScript(string key, string script) Function adds a script block into a page, that is executed after loading page in the client. The script itself does not have go be wrapped in tags <script>.
    void AddUrl(string url) Function adds a link into a page to an external file with javascript.
    void ShowHtmlDialog(string title, string html) Method displays a dialog with the passed HTML code.

    Use the function Add, if you want to add javascript into a page with form, that is changed based on various conditions or you do not want to create a special file for it.

    Use the function AddUrl, if you have javascript, that does not change or you want to use it on more pages.

    The parameter key is used for preventing inserting the same script repeatedly. If you call the method AddAddStartScript twice with the same key, then only script from the first call will be inserted.

    Example

    This script inserts a javascript into the page.

    OGForm.JavaScript.Add( 'myscript', 'var myvar="value";');

    This script displays a new tab in the browser after displaying the page and rerouts to Datas.aspx?CId=260.

    var script = 'window.open("Datas.aspx?CId=260", "_blank");';
    OGForm.JavaScript.AddStartScript( 'open-url', script);

    This script inserts a link to an external script.

    OGForm.JavaScript.AddUrl( 'http://www.mycompany.cz/myscript.js');

    This script reads values from two HTML columns, compares them and displayes the result in a dialogue

    var cl = OGModel.ClassDefs.GetById( OGActualDataRowParentId);

    var c1 = cl.Columns['text'];
    var c2 = cl.Columns['new_text'];

    var h1 = OGForm.GetControl( c1.Id).GetData();
    var h2 = OGForm.GetControl( c2.Id).GetData();

    var s = OG.TextUtils.CompareTwoHtml(h1, h2);
    OGForm.JavaScript.ShowHtmlDialog( 'Comparison of article versions', s);

     
×