Dropdown with multiple condition causing delay in editor and not updating the dropdown values

Dropdown with multiple condition causing delay in editor and not updating the dropdown values

Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

Hello.. here is my example: https://test.assettrack.cx/elevators/ele1.php

In Editor First Dropdown is Location which is working fine. The second dropdown Drawing ID is depend on first dropdown. So whatever location user select .. second dropdown drawing ID will display that particular location's drawing ids.

For e.g. If I choose Location > Avenue .. it should display only Avenue's Drawing ID in second dropdown. Which I develop correctly I guess, but in editor its showing some weird loading symbol beside the Location dropdown and its not updating at all. so I am able to apply condition on DrawingID and able to display drawing ids location wise but its not updating and editor just stop working. Please check my code below. I used editor dependent.

This is ele1.php file code

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

     $.getJSON("../ajax/at/elevDwgTagList.php",
                    {
                        location: val
                    },
                      function (data) {
                       editor.field('DrawingID').update(data);

                    }
                 );
  });

This is elevDwgTagList.php code..

<?php
include_once("../lib/DataTables.php");

    $asset = $db
        ->select(
            'asset', 
            [
            'id as value', 
            'dwgTag as label'
            ], 
            function ($q) {
            $q
                ->where(function ($r) {
                    $r->where('assetType', 1);
                    $r->or_where('assetType', 2);
                  })
                ->where('loc', $_GET['location']);

            }
        )
        ->fetchAll();

 echo json_encode( $asset );
// echo json_encode( [
//     'options' => [
//         'DrawingID' => $asset,
//     ]
// ] );
?>

This is controller file code used for Dropdown

            Field::inst( 'A.id', 'DrawingID') // To display Drawing ID Dropdown in Edit form
                    ->options( Options::inst()
                        ->table('asset')
                        ->value('id')
                        ->label('dwgTag')
                        ->where( function ($q) {
                            $q->where( 'id', 0, '!=' );
                            $q->and_where(function ($r) {

                                        $r->where('assetType', 1);
                                        $r->or_where('assetType', 2);
                                    });

                        } )
                        ->order('id')
                        )
                    // ->validator( Validate::dbValues() )
                    ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'Which Drawing ID are we updating?' )
                    ))

        ->leftJoin( 'asset A', 'A.id', '=', 'E.assetid')
        ->leftJoin( 'loc L', 'L.id', '=', 'A.loc' )
        ->leftJoin( 'users_enc U1', 'U1.id', '=', 'E.Updated_By')
        //->leftjoin( 'elevator_escalator_Status S', 'S.id', '=', 'E.elevatorStatus')
        ->leftJoin( 'assetstatus S', 'S.id', '=', 'A.assetStatus' )
        ->leftJoin( 'levels L1', 'L1.levelID', '=', 'E.higher' )
        ->leftJoin( 'levels L2', 'L2.levelID', '=', 'E.lower' )
         ->leftJoin( 'assettype T', 'A.assetType', '=', 'T.assetTypeID' )
         ->leftJoin( 'reports PC', 'PC.id', '=', 'A.picoReport' )
         ->leftJoin( 'reports SAT', 'SAT.id', '=', 'A.satReport' )

        ->debug(true)
        ->process( $_POST )
        ->json();
        ?>

Replies

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

    Thanks for your question - however, I'm getting an error when loading your page:

    DataTables warning: table id=assyntCx_Table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    Is that the problem you are having? The issue you describe above seems to suggest that you are using Editor, but I'm not seeing anywhere to trigger Editor - possibly due to the error above?

    Allan

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan Hi allan.. I set my page to public.. so anyone can view it. But when I logged out from my system.. I am also getting the same error you mention above. But If I am logged in to system .. I dont see any errors.. and its working fine. I dont know why this is happening every time.. I try to share a link of my page by making it public, without logged in to system no one can see it.. and having the same error.

    DataTables warning: table id=assyntCx_Table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan Also the actual issue has been resolved. There was some error in my code that I fixed it but by making page public.. no one is able to see it is still an issue.

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

    I'm still getting the Invalid JSON error - presumably because I'm not logged in. Perhaps you can send me login details?

    Allan

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan sorry I can not share login details for now, but can you please try below link if you are able to open and view it ?

    https://test.assettrack.cx/install.php

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

    Yes, I can see that page and it loads correctly. I don't see what it has to do with dependent() though - it doesn't appear to use Editor on that page?

    Allan

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan Yes the original question I asked in this post related to dependent() is resolved. and the above link which is loads correctly doesn't have Editor.

    My Question is is it just because of Login credential you are not able to view certain links ? and if so.. why some pages you are able to see and some are not ?

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

    I honestly couldn't say. it's your web-site - perhaps have a look at the logs? I can only presume that you have session security for your Ajax files which aren't on the main html pages.

    Allan

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan okay thank you allan, I will check logs and will try to understand whats going on.

    One last question.. Is there any example that I can use as a reference where there is use of DataTable ajax option to get the data and send the options selected using ajax.data to obtained same result as below link.

    https://test.assettrack.cx/install.php

    I checked documentation but still not clear. If you can share similar example .. that would be great.

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

    This example shows how you can send custom parameters to the server. You don't need (and probably don't want) the serverSide option - the key here is that ajax.data option.

    It doesn't show exactly what you need, but does show the concept. If you need us to build a demo for you, we offer professional support packages.

    Allan

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    As you said, you can use ajax.data to send data to the server - there are examples in that reference page.

    Colin

Sign In or Register to comment.