labels_display_on_top - subform ?

Questions related to customising nuBuilder Forte with Javascript or PHP.

labels_display_on_top - subform ?

Postby kknm » Sat May 23, 2020 8:57 pm

This snipet does not affect subform.
kknm
 
Posts: 102
Joined: Sat Apr 11, 2020 7:33 am

Re: labels_display_on_top - subform ?

Postby kev1n » Sat May 23, 2020 9:07 pm

I don't understand what your question is, what you are referring to.
kev1n
 
Posts: 728
Joined: Mon Oct 15, 2018 2:13 am

Re: labels_display_on_top - subform ?

Postby kknm » Sat May 23, 2020 9:52 pm

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
kknm
 
Posts: 102
Joined: Sat Apr 11, 2020 7:33 am

Re: labels_display_on_top - subform ?

Postby kev1n » Sun May 24, 2020 10:26 am

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
 
Posts: 728
Joined: Mon Oct 15, 2018 2:13 am

Re: labels_display_on_top - subform ?

Postby kev1n » Sun May 24, 2020 12:48 pm

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)
kev1n
 
Posts: 728
Joined: Mon Oct 15, 2018 2:13 am

Re: labels_display_on_top - subform ?

Postby kknm » Mon May 25, 2020 5:17 am

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]
Attachments
labels.PNG
labels.PNG (21.01 KiB) Viewed 67 times
kknm
 
Posts: 102
Joined: Sat Apr 11, 2020 7:33 am

Re: labels_display_on_top - subform ?

Postby kev1n » Mon May 25, 2020 6:49 am

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.
kev1n
 
Posts: 728
Joined: Mon Oct 15, 2018 2:13 am

Re: labels_display_on_top - subform ?

Postby kknm » Mon May 25, 2020 3:36 pm

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
subform.png (32.21 KiB) Viewed 58 times
[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, []);
}    
kknm
 
Posts: 102
Joined: Sat Apr 11, 2020 7:33 am

Re: labels_display_on_top - subform ?

Postby kev1n » Mon May 25, 2020 3:46 pm

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']), []);
       

kev1n
 
Posts: 728
Joined: Mon Oct 15, 2018 2:13 am

Re: labels_display_on_top - subform ?

Postby kknm » Mon May 25, 2020 6:04 pm

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.
kknm
 
Posts: 102
Joined: Sat Apr 11, 2020 7:33 am

Next

Return to Custom Code



cron