Show/Hide fields and its associated json
Show/Hide fields and its associated json
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
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
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:
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 .
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?