Welcome to the nuBuilder Forums!

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

labels_display_on_top - subform ?

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

labels_display_on_top - subform ?

Unread post by kknm »

This snipet does not affect subform.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kev1n »

I don't understand what your question is, what you are referring to.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kknm »

kev1n wrote:I don't understand what your question is, what you are referring to.
Code snippets for nuBuilder4 https://github.com/smalos/nuBuilder4-Code-Library
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kev1n »

This is because subform objects have different IDs.

The ID is composed of subform obj ID + 3 digit number + obj ID.

e.g. subformid001myobjectID
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kev1n »

Here is a new convenient function:

Code: Select all

jQuery.fn.labelOnTop = function(offsetTop = -18, offsetLeft = 0){

	return this.each(function() {
		$('#' + 'label_' + this.id).css({
			'top': parseInt($(this).css("top")) + offsetTop,
			'left': parseInt($(this).css("left")) + offsetLeft,
			'text-align': 'left'
		})		
    });	
	
};
Usage:

Position all labels of the subform with ID subfromObjID at the top of their objects:

Code: Select all

$('[id^=subfromObjID]).labelOnTop();
Position the label of the Object with ID firstname in the subform with ID subfromObjID at the top of its object:

Code: Select all

$('[id^=subfromObjID][id$=firstname]').labelOnTop();
Please do not forget to do the positioning again when a new row is added. (--> afterinsertrow event of the subform)
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kknm »

kev1n wrote:Here is a new convenient function:
It seems we again do not understand each other, communicating via google-translate.
I talked about the fact that if you put subform (grid) on the edit form, its label does not move over the subform, according to the function.
[img]
labels.PNG
[/img]
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kev1n »

It's not the language but the lack of information provided.
The screenshot is one thing. It's never wrong to post one to help us understand a question better. The other thing that is essential is to see some code.
Without knowing what your code looks like we can only guess what's going wrong.

So please show us the code you're using and also a picture of the subform properties so we can see the object ID.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kknm »

kev1n wrote: So please show us the code you're using and also a picture of the subform properties so we can see the object ID.
subform.png
[img]
subform.png
[/img]
Setup-Header:

Code: Select all

function custFieldLabelsOnTop(f, e) {

    for (var i = 0; i < f.length; i++) {
        if (jQuery.inArray(f[i], e) == -1) {

            var t = $('#' + f[i]).cssNumber("top");
            var l = $('#' + f[i]).cssNumber("left");
            $('#' + 'label_' + f[i]).css({
                'top': t - 18,
                'left': l - 15
            })
        }
    }
}

jQuery.fn.cssNumber = function(prop){
    var v = parseInt(this.css(prop),10);
    return isNaN(v) ? 0 : v;
};	
	
And on browse form:

Code: Select all

if (nuFormType() == 'edit') {
 
        var f = nuSubformObject("").fields;          // include all fields of your main form.
        custFieldLabelsOnTop(f, []);
} 	
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kev1n »

I see where the problem is. nuSubformObject("").fields doesn't contain the subform object.

Just add the subform object separately to the fields array:

Code: Select all

if (nuFormType() == 'edit') {

        var f = nuSubformObject("").fields; // include all fields of your main form.
        custFieldLabelsOnTop($.merge(f,['sub_vupusk']), []);
        
}  
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: labels_display_on_top - subform ?

Unread post by kknm »

kev1n wrote:I see where the problem is. nuSubformObject("").fields doesn't contain the subform object.

Just add the subform object separately to the fields array:

Code: Select all

if (nuFormType() == 'edit') {

        var f = nuSubformObject("").fields; // include all fields of your main form.
        custFieldLabelsOnTop($.merge(f,['sub_vupusk']), []);
        
}  
Thanks! its ok.
Post Reply