Field Set Value from a different location

Field Set Value from a different location

nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2
edited August 2016 in Editor

This calls out a computer name:

    var url = "/api/cdi_master/GetLogin";

        $.get(url, null, function (data) {
           $("#rData").val(data);
      
        });

Right now it passes to a location on my page but I would also like it to pass the value to User field in the editor below.

This is my editor code:

 var editor; // use a global for the submit and return data rendering in the examples

        $(document).ready(function () {

            editor = new $.fn.dataTable.Editor({
                "ajax": "/api/cdi_master",
                "table": "#example",
                "fields": [
        {

            label: "<div background-color=#004d99; layer-background-color:#004d99><b>Show Form Action:</b></font>",

                    name: "options",
      
            type: "radio",

            options: [ "Billing Status Only", "Add Reconciliation" ],
            def: "Billing Status Only"
        },
       {
           label: "Billing Status:",
           name: "cdi_details.billing_status",
           value: "cdi_billing_status.id",
           type: "radio"
       },
        
        { label: "Audit Status",
        name: "cdi_details.audit_status",
        value: "cdi_audit_status.id",
        type: "radio"
},
        
    {
        label: "User",
        name: "User"

    },

     {
         label: "Insurance:",
         name: "cdi_details.insurance_id",
         value: "cdi_insurance.id",
         type: "select"
     },
         {
             label: "Amount Billed",
             name: "cdi_details.amount_billed",
             def: "0.00"

         },
        {
             label: "Amount Received",
             name: "cdi_details.amount_received",
            def: "0.00"

        }, 
        {
            label: "Date Mailed",
            name: "cdi_details.date_mailed",
        type: "date",
         def: "00/00/0000"   
        },
        {
                label: "Optional Comments",
            name: "cdi_details.comment",
            type: "textarea"
        
        },

                ]
            });
         


            editor.dependent('options', function (val) {

                return val === 'Add Reconciliation' ?

            { show: ['cdi_details.insurance_id', 'cdi_details.amount_billed', 'cdi_details.amount_received', 'cdi_details.date_mailed'] } :
        { hide: ['cdi_details.insurance_id', 'cdi_details.amount_billed', 'cdi_details.amount_received', 'cdi_details.date_mailed'] }
               
           
               

                ;
        } );

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    It sounds like you just want to add editor.set( 'User' ).val( data ); in your $.get callback (assuming that function is executed while the edit view is open).

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    I did try that (probably should have posted the correct syntax, sorry about that). But I think I am a little lost as to exactly where to place the statement while the edit view is open?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I guess the key question is, at what point is your $.get executed to get the user id? Is it at page load? In which case save the value into a variable and use the initCreate and initEdit events to set the field's value:

    editor.on( 'initCreate initEdit', function () {
      editor.set( 'User' ).val( userId );
    } );
    

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    It is executed based on the user clicking on the reconcile link:
    var table = $('#example').DataTable( {
    ajax: "/api/cdi_master",
    deferRender: "true",
    "columns": [

                    {
    
                        "className":      'details-control',
                        "orderable":      false,
    
                        "data":           null,
    
                        "defaultContent": ''
    
                    }, { data: "cdi_details.client_num" },
                      { data: "cdi_details.kindid" },
         { data: "cdi_master.simon" },
                        { data: "cdi_master.cdi_master_id" },
                        { data: "cdi_master.service_date" },
                       { data: "cdi_details.name" },
                       { data: "cdi_master.ClinicianName" },
    
                       { data: "cdi_details.service_class" },
                        { data: "cdi_details.service" },
                        {
                            "class": "left",
                            "data": "cdi_master.cdi_status_id",
                            "render": function (val, type, row) {
                                return val == 4 ? "Completed" : val == 5 ? "Needs Research" : val == 1 ? "To Be Processed" : val == 2 ? "Recalled" : val == 6 ? "In Progress" : val == 3 ? "Needs Attention" : ""
                            }
                        },
                         {
    
                             data: null, 
    
                             className: "center",
    
                             defaultContent: '<a href="" class="editor_edit">Reconcile</a>'
    
                         }
    
                ]
            })
    
  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Unable to get property 'get' of undefined or null reference

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Solved my own problem and posting for whoever needs something like this. Using editor.set will not work. The following does work :) :

                editor.edit('initEdit', function () {
                    $.get(url, null, function (data) {
                        editor.field('User').def(data);
    
                    });
    
                });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for posting back with your solution.

    Allan

This discussion has been closed.