Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Restric updating field.

Questions related to using nuBuilder Forte.
sandeepgumudelli
Posts: 41
Joined: Thu Jan 25, 2018 3:51 pm

Restric updating field.

Unread post by sandeepgumudelli »

Hi,

once data is inserted, can we restrict update on that field??

Regards,
Sandeep
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Restric updating field.

Unread post 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
sandeepgumudelli
Posts: 41
Joined: Thu Jan 25, 2018 3:51 pm

Re: Restric updating field.

Unread post by sandeepgumudelli »

How can we use this in Sub form which is in grid format??
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Restric updating field.

Unread post by toms »

Just add the code to your main form and all fields of your subform will also be included (/disabled)
sandeepgumudelli
Posts: 41
Joined: Thu Jan 25, 2018 3:51 pm

Re: Restric updating field.

Unread post 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#.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Restric updating field.

Unread post 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);
sandeepgumudelli
Posts: 41
Joined: Thu Jan 25, 2018 3:51 pm

Re: Restric updating field.

Unread post 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.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Restric updating field.

Unread post 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
You do not have the required permissions to view the files attached to this post.
sandeepgumudelli
Posts: 41
Joined: Thu Jan 25, 2018 3:51 pm

Re: Restric updating field.

Unread post 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??
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Restric updating field.

Unread post 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
	}
}
Last edited by Anonymous on Thu Jul 19, 2018 2:52 pm, edited 1 time in total.
Locked