Page 1 of 2
Restric updating field.
Posted: Wed Jul 18, 2018 3:13 pm
by sandeepgumudelli
Hi,
once data is inserted, can we restrict update on that field??
Regards,
Sandeep
Re: Restric updating field.
Posted: Wed Jul 18, 2018 3:30 pm
by toms
Hi,
You can disable fields with Javascript (not so secure but simple) and in addition, to make it more secure, check by PHP if no other fields have been modified.
Add this to you form's JavaScript field:
Code: Select all
if(!nuIsNewRecord()){
// Disable all fields
$('input, select, textarea').prop('disabled', true);
// Enable just one field
$('#some_field_id').prop('disabled', false);
}
...and something like this in PHP:
https://forums.nubuilder.cloud/viewtopic. ... ent#p17256
Re: Restric updating field.
Posted: Wed Jul 18, 2018 3:35 pm
by sandeepgumudelli
How can we use this in Sub form which is in grid format??
Re: Restric updating field.
Posted: Wed Jul 18, 2018 3:38 pm
by toms
Just add the code to your main form and all fields of your subform will also be included (/disabled)
Re: Restric updating field.
Posted: Wed Jul 18, 2018 5:00 pm
by sandeepgumudelli
Thank you very much for response Tom.
if(!nuIsNewRecord()){
// Disable all fields
$('input, select, textarea').prop('disabled', true);
// Enable just one field
$('#some_field_id').prop('disabled', false);
}
from this code #some_field_id is from main form it is working.
if i use #some_field_id subform field it is not working.
if the field name is customer_name from subform i tried with ,
customer_name,#customer_name, #customer_name#.
Re: Restric updating field.
Posted: Wed Jul 18, 2018 5:04 pm
by toms
replace sub_form_id with the
ID of your subform:
Code: Select all
$('[id ^=sub_form_id][id $=customer_name]').prop("disabled", false);
Re: Restric updating field.
Posted: Thu Jul 19, 2018 10:28 am
by sandeepgumudelli
Something i must be doing wrong... I tried all the ways but no luck. Today i will try will secure way using PHP.
Re: Restric updating field.
Posted: Thu Jul 19, 2018 11:00 am
by toms
It works for me, e.g. in the "Access Levels" / Tab Forms , disable all Add checkboxes:
Code: Select all
$('[id ^=accform][id $=slf_add_button]').prop("disabled", true);
test.png
Re: Restric updating field.
Posted: Thu Jul 19, 2018 12:58 pm
by sandeepgumudelli
Yeah it working now. with java script.
because of the condition if(!nuIsNewRecord()) it is not allowing me to add new sub form record if i edit main form.
I need it like:
when we edit main form it should allow us to add new subform record with all the fields enable to enter but not to edit exiting sub form field data.
will that be possible??
Re: Restric updating field.
Posted: Thu Jul 19, 2018 2:07 pm
by toms
sandeepgumudelli wrote:
when we edit main form it should allow us to add new subform record with all the fields enable to enter but not to edit exiting sub form field data.
will that be possible??
That's possible. All you need to know is some JavaScript/jQuery and use functions the are documented on the wiki.
https://wiki.nubuilder.cloud/ ... Javascript
Code: Select all
function disableSubformRows(f) {
// disable all fields of the subform grid
$('[id ^=' + f + ']').prop("disabled", true);
// enable the last row to allow new insertions
var r = nuPad3(nuSubformObject(f).rows.length - 1);
$('[id ^=' + f + r + ']').prop("disabled", false);
}
if (nuFormType() == 'edit') { // run the script if the form type is edit
if (!nuIsNewRecord()) { // disable rows if not a new record
disableSubformRows("YOUR_SUB_FORM_ID"); // <------------- replace with your subform id
}
}