Page 1 of 2

labels_display_on_top - subform ?

Posted: Sat May 23, 2020 1:27 pm
by kknm
This snipet does not affect subform.

Re: labels_display_on_top - subform ?

Posted: Sat May 23, 2020 1:37 pm
by kev1n
I don't understand what your question is, what you are referring to.

Re: labels_display_on_top - subform ?

Posted: Sat May 23, 2020 2:22 pm
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

Re: labels_display_on_top - subform ?

Posted: Sun May 24, 2020 2:56 am
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

Re: labels_display_on_top - subform ?

Posted: Sun May 24, 2020 5:18 am
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)

Re: labels_display_on_top - subform ?

Posted: Sun May 24, 2020 9:47 pm
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]

Re: labels_display_on_top - subform ?

Posted: Sun May 24, 2020 11:19 pm
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.

Re: labels_display_on_top - subform ?

Posted: Mon May 25, 2020 8:06 am
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, []);
} 	

Re: labels_display_on_top - subform ?

Posted: Mon May 25, 2020 8:16 am
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']), []);
        
}  

Re: labels_display_on_top - subform ?

Posted: Mon May 25, 2020 10:34 am
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.