Page 1 of 1
Read only after save / Also nested access levels
Posted: Fri Nov 06, 2015 3:42 am
by mobilemcclintic
Hello,
is there a way to make a record read only after it has been saved, or in a different circumstance to allow only certain groups to edit?
In my case, I have an item request main form, and comments sub form. I would like if a user creates a comment, that after they save the field is read only.
In the request main form, I would like some fields to be read only, and others to be editable depending on the logged in user.
I was looking at nuDisable(object) but i can never figure out where to put the pieces of code and how to make it work. Is there actual tutorials on how and where to use php script, html code and js? Watching some done would be awesome.
Re: Read only after save / Also nested access levels
Posted: Fri Nov 06, 2015 3:56 am
by mobilemcclintic
Just so other people can see what I am trying to do in case they are looking for ideas, on my forms and related tables I have an
author field (user_name)
author group field (hidden, user's group)
target group (visible, target audience's user group)
My hope for viewing records is to add in the browse mysql a where statement that says the record should have the author group or target group match the logged in user's group in order to remove some of the records the user doesn't need to see or act on.
I.E select * from table where table.author_group = #nu_user_group# OR table.target_group = #nu_user_group#
For captains or other high level people (admin), I'll clone the form with either a full browse, or otherwise broader where clause.
Re: Read only after save / Also nested access levels
Posted: Fri Nov 06, 2015 5:58 am
by david
Just a quick idea.
It looks like you want to make some fields readonly on load of your form, depending on some conditions.
For your form, I would add to nuLoadEdit() in JavaScript and make the fields readonly using normal / standard JavaScript if they do not have sufficient privileges.
Quick example js:
Code: Select all
function nuLoadEdit(){
if('#nu_access_level#' != 'Admin' && '#nu_access_level#' != 'globeadmin'){
$('#fieldname').prop('readonly',true);
}
}
Re: Read only after save / Also nested access levels
Posted: Sat Nov 07, 2015 1:56 am
by mobilemcclintic
Thank you David, that works great.
Can this functionality be applied to a grid style subform?
The subform doesn't show up in forms, and if I pull it up in objects, it doesn't have a custom code section.
IE, I only want Bob to be able to edit his own comments:
Comment Comment Author
Blah Blah Blah Bob (can edit)
Check Check Brewster (can not edit)
[EDITED BELOW 11/6/2015] Previous code disallowed editing any field because the auther wasn't saved into the record yet.
For other newer developers, I have a form that an initial user fills out and saves. Another person can edit only one field on that form. Read only fields are defined for everyone on the form (create date, author) and below:
function nuLoadEdit(){
if('#nu_user_name#' != '#FORMAUTHORFIELD#' && '#RECORD_ID#' != -1){
$('#DROPDOWN1').prop('disabled',true);
$('#DROPDOWN2').prop('disabled',true);
$('#DROPDOWN3').prop('disabled',true);
$('#DATEPICKER').prop('disabled',true);
$('#TEXTFIELD1').prop('readonly',true);
$('#TEXTFIELD2').prop('readonly',true);
}
}
Re: Read only after save / Also nested access levels
Posted: Mon Dec 07, 2015 11:09 pm
by admin
mobilemcclintic,
To do it for all the fields in a subform you will need to loop through the rows and prefix the field name with the row's prefix.
You can use nuSubformArray() to do this..
http://wiki.nubuilder.net/nubuilderv3/i ... true.5D.29
Steven
Re: Read only after save / Also nested access levels
Posted: Fri Feb 19, 2016 7:08 am
by mobilemcclintic
I hate to add to this post, but it is related.
Using the example you helped me with property controls based on users or if it was a new record or not, I tried to add the functionality to another form that has HTML framesets.
After I add the code to enable/disable/readonly a field based on user, two things happened.
The framesets all anchored themselves to 0,0 (I had them set at specific points).
The rest of the fields took a normal vertical stack regardless of my positioning coordinates.
I reset the HTML framesets so the top and left coordinates were in the html code themselves, but the fields still stayed in a vertical column.
I can post the code tomorrow.
Re: Read only after save / Also nested access levels
Posted: Fri Feb 19, 2016 4:06 pm
by mobilemcclintic
I forgot to include NU in front of system variables, so that may have been the problem.
Re: Read only after save / Also nested access levels
Posted: Sat Feb 20, 2016 3:13 am
by mobilemcclintic
Hello, I tried following the above and another thread that had slightly different circumstances, but am struggling. I'm hoping a fellow member could help me out.
I have essentially 4 sections in my code.
First I have a mouse hover label section, which works.
Second i have a single control controlled by user names. "TSTSR" can only be changed by globeadmin, mistyd, andread, dmaysd, and jamesd. This works.
Third I have controls set for if "tscomplete" on the main form is checked (1) it makes the controls in that section not function (not sure if I MUST use readonly, but disabled seems to work.
After that I have what I thought would work for making the rows in my subform read only (grid style, one field only while I try to figure it out). This part does nothing.
Essentially, if "tscomplete" on the main form "sqllog" is checked (1), I want the subform's field "sqdpn" to be readonly or disabled for each row. I am hoping someone has done something similar and can show an example. Another thread had a checkbox on the subform's row, which wouldn't really work that well in this case, because the rows are pretty fluid until the whole form is filled and complete.
Code: Select all
function nuLoadEdit() {
showTooltip("tssappn", "Enter system PN that corresponds to the Quoted PN", false);
showTooltip("tsqtpn", "Enter an equivalanet part \n\n Volcano can offer the customer that will satisfy their needs.", false);
if('#nu_user_id#' != 'globeadmin' || '#nu_user_id#' != 'mistyd' || '#nu_user_id#' != 'andread' || '#nu_user_id#' != 'dmaysd' || '#nu_user_id#' != 'jamesd')
{
$('#tstsr').prop('readonly',true);
}
if('#tscomplete#' == '1'){
$('#tsqtpn').prop('disabled',true);
$('#tsdesc').prop('disabled',true);
$('#tsqtcnd').prop('disabled',true);
$('#tsqtqty').prop('disabled',true);
$('#tssappn').prop('disabled',true);
$('#tsqtcost').prop('disabled',true);
$('#tsqtlead').prop('disabled',true);
$('#tsqtleadunit').prop('disabled',true);
$('#tsrnotes').prop('disabled',true);
$('#tstsr').prop('disabled',true);
var subFormPrefixes = nuSubFormArray('#sqldetail_subform');
for (var index in subFormPrefixes){
$('#'+subFormPrefixes[index]+'.sqdpn').prop('disable',true);
}
}
}
Re: Read only after save / Also nested access levels
Posted: Mon Feb 22, 2016 9:07 pm
by mobilemcclintic
With some creative thinking, I worked around this issue by cloning the subform and its objects as read only, and showed the main subform when my complete checkbox is unchecked and the secondary one when the box is checked. Really would have liked the same Custom Code tab for the subforms that are on the main forms, but this will work.
Thank you
Re: Read only after save / Also nested access levels
Posted: Mon Feb 22, 2016 10:25 pm
by admin
.