Readonly, but not for a specific group
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Readonly, but not for a specific group
Hi,
I'd like to be able to set a field to Read Only (in the AppGini Console), but still allow members of the Admins (and/or other groups) to edit that same field. I have searched for solutions in this forum, but none seems to work (for me at least). Is there a definitive way for doing this?
Thanks
I'd like to be able to set a field to Read Only (in the AppGini Console), but still allow members of the Admins (and/or other groups) to edit that same field. I have searched for solutions in this forum, but none seems to work (for me at least). Is there a definitive way for doing this?
Thanks
Re: Readonly, but not for a specific group
Hi,
if it is for one field only I would guess that this is not possible via the AppGini Console. Also be aware that if you set a field to readonly via the AppGini console, that field is not getting saved to the database, even if you change the fieldvalue via script (Unless you hook the SQL to store the data).
if it is for one field only I would guess that this is not possible via the AppGini Console. Also be aware that if you set a field to readonly via the AppGini console, that field is not getting saved to the database, even if you change the fieldvalue via script (Unless you hook the SQL to store the data).
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi pböttcher,
Thanks for the reply.
No, this would not be for one field only, but for many. And they don't have to be set to read only from the console. It would be more convenient though. I tried following some of the posts on this issue, but the proposed solutions didn't work for me. Not sure why.
Thanks
Thanks for the reply.
No, this would not be for one field only, but for many. And they don't have to be set to read only from the console. It would be more convenient though. I tried following some of the posts on this issue, but the proposed solutions didn't work for me. Not sure why.
Thanks
Re: Readonly, but not for a specific group
Hi,
maybe you describe a litte more what your need is (shown by a screenshot helps a lot).
maybe you describe a litte more what your need is (shown by a screenshot helps a lot).
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi,
I have table called Participants with several fields that I'd like to make read only, but only to a group of users called Registrars. So, when a user in the Registrars group logs in, he/she should be able to see these fields in read only mode and not be able to modify their content. Whereas, if a user from the Admins (or another group called SuperAdmins) logs in, he/she should have the possibility to modify these fields.
A couple of fields are FirstName, FamilyName, Email, etc..., but let one work and I think the others would then be no problem.
I tried adding the following code (taken from a post on this forum) to my Participants.php file in the hooks folder, but it didn't help:
Thanks
I have table called Participants with several fields that I'd like to make read only, but only to a group of users called Registrars. So, when a user in the Registrars group logs in, he/she should be able to see these fields in read only mode and not be able to modify their content. Whereas, if a user from the Admins (or another group called SuperAdmins) logs in, he/she should have the possibility to modify these fields.
A couple of fields are FirstName, FamilyName, Email, etc..., but let one work and I think the others would then be no problem.
I tried adding the following code (taken from a post on this forum) to my Participants.php file in the hooks folder, but it didn't help:
In fact, if use the code above, I get the error:function Participants_dv($selectedID, $memberInfo, &$html, &$args){
/* current user is not an admin? */
if($mi['group'] != 'Admins'){
$html .= <<<EOC
<script>
\$j(function(){
\$j('#Email').prop('readonly', true);
})
</script>
EOC;
}
}
So, I'm quite lostParse error: syntax error, unexpected '<<' (T_SL) in /.............../hooks/Participants.php on line 183
Thanks
Re: Readonly, but not for a specific group
Setting an INPUT readonly depends on a few parameters like the used DOCTYPE and the jquery version.
Can you please try...
...or...
...or...
I guess the second version will work.
This is for INPUTs only. Dynamically loaded dropdowns (Lookup fields) cannot be handled like this.
Hope one of the alternatives works for you!
Regards,
Jan
Can you please try...
Code: Select all
.prop('readonly', 'readonly');
Code: Select all
.attr('readonly', 'readonly');
Code: Select all
.attr('readonly', true);
This is for INPUTs only. Dynamically loaded dropdowns (Lookup fields) cannot be handled like this.
Hope one of the alternatives works for you!
Regards,
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi,
Thanks. At the moment, however all I get is the parsing error:
Thanks. At the moment, however all I get is the parsing error:
I tried to simplify the code onto one line:Parse error: syntax error, unexpected '<<' (T_SL) in /................/hooks/Participants.php on line 182
But the error persists!function Participants_dv($selectedID, $memberInfo, &$html, &$args){if($mi['group'] != 'Admins'){$html.=<<<EOC <script> \$j(function(){\$j('#Email').prop('readonly', 'readonly');})</script>EOC;}}
Re: Readonly, but not for a specific group
Hi,
your first version is fine, but the error seems to indicate that there is something wrong with your HEREDOC.
Can you please verify that there is no extra character after the HEREDOC "EOC" in your first version.
your first version is fine, but the error seems to indicate that there is something wrong with your HEREDOC.
Can you please verify that there is no extra character after the HEREDOC "EOC" in your first version.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi.
I restored to the original code:
Thanks
I restored to the original code:
I would like to share a screenshot from Notepadd++, but don't know how to do so. All I have is CR-LF directly after the EOC. Notepad++, however, shows that the function does not end. As soon as I add a space after the EOC, Notepad++ is fine again. But with or without space, both versions cause the parse error from the server!function Participants_dv($selectedID, $memberInfo, &$html, &$args){
if($mi['group'] != 'Admins'){
$html.=<<<EOC
<script>
\$j(function(){
\$j('#Email').prop('readonly', 'readonly');
})
</script>
EOC;
}
}
Thanks
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
You can try to download the screenshot from:
https://www.dropbox.com/s/yn61h1k2dg383 ... 1.jpg?dl=0
https://www.dropbox.com/s/yn61h1k2dg383 ... 1.jpg?dl=0
Re: Readonly, but not for a specific group
Hmmm, strange,
can you try this:
can you try this:
Code: Select all
function Participants_dv($selectedID, $memberInfo, &$html, &$args){
if($mi['group'] != 'Admins'){
ob_start(); ?>
<script>
$j(function(){
$j('#Email').prop('readonly', 'readonly');
})
</script>
<?php
$new_layout = ob_get_contents();
ob_end_clean();
$html .= $new_layout;
}
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Readonly, but not for a specific group
Hi again,
after reviewing your screenshot, I think you need to put the "EOC" for the end delimiting at the start of the line without tabs. The screenshot shows two tabs. You may try this as well.
after reviewing your screenshot, I think you need to put the "EOC" for the end delimiting at the start of the line without tabs. The screenshot shows two tabs. You may try this as well.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi,
So, some progress! Removing the two tabs removed the parsing error.
I tried however all variations of .prop .attr above and also the other code, but in all cases, the field is read only, but also for the Admins group!
I'm logged in to the project using different browsers, one with a normal user and the other with a user from the Admins group. Both cases show the file Email as read only.
Thanks
So, some progress! Removing the two tabs removed the parsing error.
I tried however all variations of .prop .attr above and also the other code, but in all cases, the field is read only, but also for the Admins group!
I'm logged in to the project using different browsers, one with a normal user and the other with a user from the Admins group. Both cases show the file Email as read only.
Thanks
Re: Readonly, but not for a specific group
Hi,
you need to refere to $memberInfo not $mi in your code.
you need to refere to $memberInfo not $mi in your code.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Eureka!!!
Thank you so much. Works now!
Much appreciated.
Thank you so much. Works now!
Much appreciated.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Ok. Now that this is fixed for input fields, how can I do it also for dropdowns and checkboxes?
Re: Readonly, but not for a specific group
Hi,
try
$j("#ELEMENT-container").attr('disabled',true);
where you replace ELEMENT by the name of your dropdown.
For checkboxes you should use the same as for an input field.
$j("#ELEMENT").attr('disabled',true);
try
$j("#ELEMENT-container").attr('disabled',true);
where you replace ELEMENT by the name of your dropdown.
For checkboxes you should use the same as for an input field.
$j("#ELEMENT").attr('disabled',true);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi,
My Participants table has the following two fields:
Thanks
My Participants table has the following two fields:
- countrykey which calls on a lookup table; and
- Gender which allows a selection between Male and Female (not lookup)
Code: Select all
$j("#countrykey-container").attr('disabled',true);
$j("#Gender-container").attr('disabled',true);
Re: Readonly, but not for a specific group
Hi,
what browser are you using? Can you post a screenshot of the debugger that shows your fields.
what browser are you using? Can you post a screenshot of the debugger that shows your fields.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Hi,
I use Chrome and Edge. The code screenshot is from Notepad++. You can download the screenshots from here:
I use Chrome and Edge. The code screenshot is from Notepad++. You can download the screenshots from here:
- https://www.dropbox.com/s/y0wjn6u6l9vn8 ... 1.jpg?dl=0
Screenshot from Notepad++ showing the two lines that do not work (countrykey and Gender);
- https://www.dropbox.com/s/8wqb7tjamepbw ... 2.jpg?dl=0
Screenshot from AppGini console showing the definition for the field countrykey; and
- https://www.dropbox.com/s/anskzha0yhce5 ... 3.jpg?dl=0
Screenshot from AppGini console showing the definition for the field Gender.
Re: Readonly, but not for a specific group
Do the select-containers exist at the moment you try to change the attribute?
You can check this by inserting the following line BEFORE your .attr(...) code:
I guess there will be "0" in the console output window which means the #countrykey-container does not exist, yet. That's because the dropdown controls are being created dynamically after the page has loaded. They are not available in your $j(function() { ...} ), yet.
There is a similar post here:
https://forums.appgini.com/phpbb/viewto ... down#p9289
Some developers here are using a timer to do the changes let's say 1000 milliseconds after document-ready. You may have a look at setTimeout() and setInterval() functions.
Hope this helps!
Regards,
Jan
You can check this by inserting the following line BEFORE your .attr(...) code:
Code: Select all
console.log($j("#countrykey-container").length);
There is a similar post here:
https://forums.appgini.com/phpbb/viewto ... down#p9289
Some developers here are using a timer to do the changes let's say 1000 milliseconds after document-ready. You may have a look at setTimeout() and setInterval() functions.
Hope this helps!
Regards,
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
Thanks Jan,
I have a very stupid and ignorant question :
Where should the output of the console.log() appear? I don't see it when I refresh the browser.
Thanks
I have a very stupid and ignorant question :
Where should the output of the console.log() appear? I don't see it when I refresh the browser.
Thanks
Re: Readonly, but not for a specific group
In chrome press F12 and look at the consol-tab
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Readonly, but not for a specific group
OK, no problem - there is no stupid question!
Hope this helps!
Regards,
Jan
- In your browser open the developer tools.
Press F12-key on your keyboard. This should work in most modern browsers eg. Chrome. - After a couple of seconds there will be an additional panel on the right hand side or at the bottom. There will be several tabs
- Select the Console tab.
- Now reload the page.
You will see debug messages, warning and errors there.
Hope this helps!
Regards,
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Readonly, but not for a specific group
All resolved!
After reading your reply googling and playing around, I managed to resolve everything by using the following:
Hope this helps others as well.
Thank you both for all your help!!
After reading your reply googling and playing around, I managed to resolve everything by using the following:
Code: Select all
$j('#Field1').prop('readonly', 'readonly'); /* input fields */
$j("#Field2").attr('disabled',true); /* check boxes */
setTimeout('$j("#s2id_Field3-container").select2("readonly",true);',500); /* lookup tables */
setTimeout('$j("#s2id_Field4").select2("readonly",true);',500); /* lists */
Thank you both for all your help!!