Show/Hide fields and its associated json

Show/Hide fields and its associated json

INTONEINTONE Posts: 153Questions: 58Answers: 6
edited January 2018 in Editor

I do not want to show a certain field created by a join. That is easy. I can easily do editor.field('merchant[].merchantID').hide() on the client side. There is still an issue however, in the console the data object still exists. Is there a way to not show that data? That should not be too difficult, I should be able to do something like this:

   $data = Editor::inst( $db, 'user', 'userID' )
   ->fields(...)
   ->join(
        Mjoin::inst( 'merchant' )
            ->link( 'user.userID', 'userMerchantLink.userID' )
            ->link( 'merchant.merchantID', 'userMerchantLink.merchantID' )
            ->order( 'name asc' )
            ->fields(
                Field::inst( 'merchantID' )
                    ->validator( 'Validate::required' )
                    ->options( Options::inst()
                        ->table( 'merchant' )
                        ->value( 'merchantID' )
                        ->label( 'name' )
                    ),
                Field::inst( 'name' )
            )
    );
$out = $data->process( $_POST )->data();
if(isset($_POST['action']) && $_POST['action'] !== "remove" ){
    // check if this is an admin then if not admin
    //1. do for loop and set each merchant.merchantID to empty array
   //2. set options object as an empty object 
}

The only issue I now have is that when the user makes a post the merchant[].merchantID will be empty. I only wanted to hide the data not alter the data. So my question is how do I achieve this?

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I'm afraid I don't fully understand. Can you show me the data as it is just now, and also the data as you want it to be? I'm not clear on if its the data you submit to the server or the data the server returns that needs to be altered, and in what way.

    Thanks,
    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    What I am trying to achieve is this. If I am not an admin, when I login, I should only see the merchant that are my merchants. I should not see that there are 200 merchants. I should only see the 10 merchants that are relevant to me, then I can select as much as needed for my dataset. My initial thought was to hide the merchant list so as to prevent the user from see the list but as stated before the developer tools allow a person with a little know how to see the json. So to be clearer is there a way to filter the options list that is build from an mjon. I know the mjon does at least two things, create a general options list (the list I want to filter) and a list of already selected values. so my simple json looks like this:

    {
        "data": [{
            "DT_RowId": "row_2",
            "user": {
                "userID": "2",
                "username": "someeamil@gmail.com",
                "userType": "3",
                "firstName": "Tennesha",
                "lastName": "Stewart",
                "active": "YES",
                "createResetPassword": "NO",
                "createdAt": "7 Jul 2017 22:57",
                "updatedAt": "14 Jan 2018 11:17",
                "createdBy": "Leocrawf Stewart",
                "updatedBy": "Leocrawf Stewart",
                "deleted": "false"
            },
            "userType": {
                "name": "MERCHANT"
            },
            "merchant": [{
                "merchantID": "3",
                "name": "Mother's"
            }]
        }],
        "options": {
            "user.userType": [{
                "label": "MERCHANT",
                "value": "3"
            }],
            "merchant[].merchantID": [{
                "label": "Burger King",
                "value": "1"
            }, {
                "label": "Mother's",
                "value": "3"
            }, {
                "label": "Pizza Hut",
                "value": "4"
            }, {
                "label": "Tastee Ltd",
                "value": "2"
            }]
        },
        "files": []
    }
    
    
  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    Hello Allan,

    What I really want to do is not show the full merchant[].merchantID options list to a none admin user. At first I was thinking to hide the merchant[].merchantID options list from the user and programmatically add the only one option that he can select, but there may be cases when he will have more than one option, so hiding the merchant[].merchantID will not work. I need to only show the relevant options to a none admin user for merchant[].merchantID. Is there a way to do that in the mjoin by using a where clause? I tried it but it did not work. Here is my sample json .

    {
        "data": [{
            "DT_RowId": "row_2",
            "user": {
                "userID": "2",
                "username": "someemail@gmail.com",
                "userType": "3",
                "firstName": "Tennesha",
                "lastName": "Stewart",
                "active": "YES",
                "createResetPassword": "NO",
                "createdAt": "7 Jul 2017 22:57",
                "updatedAt": "14 Jan 2018 11:17",
                "createdBy": "Leocrawf Stewart",
                "updatedBy": "Leocrawf Stewart",
                "deleted": "false"
            },
            "userType": {
                "name": "MERCHANT"
            },
            "merchant": [{
                "merchantID": "3",
                "name": "Mother's"
            }]
        }],
        "options": {
            "user.userType": [{
                "label": "MERCHANT",
                "value": "3"
            }],
            "merchant[].merchantID": [{
                "label": "Burger King",
                "value": "1"
            }, {
                "label": "Mother's",
                "value": "3"
            }, {
                "label": "Pizza Hut",
                "value": "4"
            }, {
                "label": "Tastee Ltd",
                "value": "2"
            }]
        },
        "files": []
    }
    
  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    To be even more clearer, lets say I am the user who is logged in for burger king and pizza hut. I want to only see burger king and pizza hut listed in merchant[].merchantID:

    ``js
    "options": {
    "user.userType": [{
    "label": "MERCHANT",
    "value": "3"
    }],
    "merchant[].merchantID": [{
    "label": "Burger King",
    "value": "1"
    }, {
    "label": "Pizza Hut",
    "value": "4"
    }]
    }
    ```

    So how do I do that filter?

This discussion has been closed.