Welcome to the nuBuilder Forums!

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

Subform with specific numbers of records

Questions related to using nuBuilder Forte.
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Subform with specific numbers of records

Unread post by gerese »

Hi,
How can I limit the subform for only 10 records ?

Thanks
nuBuilderForte .... BIG Like !!!
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Subform with specific numbers of records

Unread post by kev1n »

Modify the Browse SQL and add a LIMIT 10 to the SQL.

E.g.

Code: Select all

SELECT * FROM your_table LIMIT 10
Janusz
nuBuilder Team
Posts: 508
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 10 times
Been thanked: 18 times

Re: Subform with specific numbers of records

Unread post by Janusz »

Hi,
One of the solution is to work directly on the MariaDB database tables.
You can do that by setting sob_subform_add flag directly in the zzzzsys_object table.
So in the PHP BEFORE EDIT you need to place php code which in the first step will check the qty of subform records and later depending on the value will the set sob_subform_add to 1 or 0
(maybe you should add autosave operation after every single record is added to avoid multiple entries - for example: someone can add 20records and save afterwards)

Code belowe it's just a quick trial on my application - and it's working fine. Of course in you case you need to rework it acc. to your table structure (to count records).

Code: Select all

// Place this in the PHP BE - adjust to your specific mysql tables

// count how many raws has subform for specific record
$s = "SELECT COUNT(*) AS qty FROM connection WHERE con_part='#parts_id#'";
$t  = nuRunQuery($s);
$qty  = db_fetch_object($t)->qty;

// set up  the addable value for the subform depending on the quantity value
if ($qty>10)
{$s  = "UPDATE zzzzsys_object SET sob_subform_add=0 WHERE sob_all_id='sub_FF_parts'";
$t  = nuRunQuery($s);}
else 
{$s  = "UPDATE zzzzsys_object SET sob_subform_add=1 WHERE sob_all_id='sub_FF_parts'";
$t  = nuRunQuery($s);}
If you like nuBuilder, please leave a review on SourceForge
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Subform with specific numbers of records

Unread post by gerese »

Thanks for reply Kev1n,
In fact I want for this subform in edit mode.
After 10 recordings, the empty row will be deactivated or disappear.

Thanks
You do not have the required permissions to view the files attached to this post.
nuBuilderForte .... BIG Like !!!
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Subform with specific numbers of records

Unread post by kev1n »

Add this function to your form's custom code:

Code: Select all


function subFormLimitNumberOfRows() {
    
   const MAX_ROWS = 8;
   var sf = 'your_subform_id'; // <---- replace with you subform object id         
   if (nuSubformObject(sf).rows.length > MAX_ROWS) {
	var prefix = sf + nuPad3(i);
	$("id^='" + prefix + "_" + MAX_ROWS + "").remove();   
   }
		  
}
Next, add an afterinsertrow event to your subform as shown here:

https://forums.nubuilder.cloud/viewtopic. ... row#p15460

and call the function from there:

Code: Select all

subFormLimitNumberOfRows()
In addition, call subFormLimitNumberOfRows(); when the form is loaded.
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Subform with specific numbers of records

Unread post by gerese »

Thanks Janusz, I would have liked something in javascript, simpler.

PS - We posted both at the same time :lol:
nuBuilderForte .... BIG Like !!!
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Subform with specific numbers of records

Unread post by gerese »

Cool Kev1n , you save my life , this is what I want .
nuBuilderForte .... BIG Like !!!
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Subform with specific numbers of records

Unread post by kev1n »

gerese wrote:Cool Kev1n , you save my life , this is what I want .
You're welcome :)

PS: If you really want to prevent a user from adding more than 10 rows, you need to do a server-side check. E.g. use the PHP Before Save event and retrieve the number of rows. If they exceed a certain number, abort the saving.
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Subform with specific numbers of records

Unread post by gerese »

Please Kevin, I need some help. :? :? :?
Subform id is "brn_gestiune_sf".
I set up: "const MAX_ROWS = 4"
After 4 records, the error appears.
You do not have the required permissions to view the files attached to this post.
nuBuilderForte .... BIG Like !!!
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Subform with specific numbers of records

Unread post by kev1n »

Try this one:

Code: Select all

function subFormLimitNumberOfRows() {
   
   const MAX_ROWS = 4;
   var sf = 'brn_gestiune_sf'; 
   if (nuSubformObject(sf).rows.length > MAX_ROWS) { 
       $("[id^='" + sf + nuPad3(MAX_ROWS) + "']").remove();
   }
       
}
Post Reply