Please help! Problem with Custom form's Init_fields_v2()

Forums SPJS-Utility Please help! Problem with Custom form's Init_fields_v2()

This topic contains 3 replies, has 2 voices, and was last updated by  Alexander Bautz 2 months, 4 weeks ago.

  • Author
    Posts
  • #16534

    Nan Duangnapa
    Participant

    Hi Alex and all,

    I’m new to SPJS and need to implement exact solution for my site to display another list columns.

    http://spjsblog.com/2013/10/16/display-information-from-another-list-based-on-a-lookup-column-connection-updated-version/

    I understand that I need 2 .js files;
    PullInformationFromConnectedList.js
    spjs-utility.js

    However, I also need to modify the init_fields()_v2 function in order for the demo code to work with my custom form site.
    Refer to http://spjsblog.com/2010/01/25/how-to-use-these-scripts-in-a-customized-form/

    Here is what I did
    1)I have replaced this function in my spjs-utility.js.

    function init_fields_v2(){
    var res = {};
    $(“td.ms-formlabel”).each(function(){
    var thisID = this.id;
    res[thisID] = $(this).parents(‘tr:first’);
    });
    return res;
    }

    2) I added custom Id to the ‘s formlabel which I only insert 1 place in my create new form.
    <td width=”190px” valign=”top” class=”ms-formlabel” id=”StatusCustomID”>

    3) I added the following to the CEWP in custom form site:

    fields = init_fields_v2();
    var myCompanyField = $(fields[‘StatusCustomID’]);
    alert(myTitleField.html());

    I follow the rest of steps as arrFinAndDispName function.

    Results:
    alert(myTitleField.html()) shows “undefined”
    Nothing display on my new form.

    Did I do anything wrong?
    Thank you so much

    NanD

  • #16545

    Alexander Bautz
    Keymaster

    Hi,
    I think you have mixed up the variables – you assign the value to “myCompanyField” but alerts “myTitleField”. Try alerting “” instead.

    If this don’t work, you can try using the developer console (hit F12 > Console) and type this in the console to see if the fields object contains your fields:

    fields

    Hit enter and look at the output.

    Alexander

  • #16547

    Nan Duangnapa
    Participant

    Thank you so much Alex.

    I had fixed the code and the alert shows [object object]. Is it supposed to show this?

    Besides this, are my above steps correct? especially editing init_fields_V2() in spjs-unitilty.js while leaving the init_fields() function in the file?

    Thank you so much

  • #16674

    Alexander Bautz
    Keymaster

    Hi,
    Sorry for the late reply. The alert [object object] means it is an object type an not a string. You can use console.log(PUT_VARIABLE_HERE) to see what the variable contains. Please note that you must have the developer console open (hit F12 > Console) to see the output.

    Alexander

You must be logged in to reply to this topic.