Welcome to the nuBuilder Forums!

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

#RECORD_ID# from a subform object

Questions related to using nuBuilder Forte.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

Try this instead:

Code: Select all

function nuSelectBrowse(e) {
    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    window.ENTREPRISE_ID = r;
    nuForm(nuGetProperty('form_id'), r, '', '', '1');   
}
...and then:

Code: Select all

if (nuFormType() == 'edit') {
    $("#contact_entreprise_id").val(window.ENTREPRISE_ID).change(); 
}
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

Thanks toms. It works! Though there is one side effect:

The enterprise id is pre-entered on the 2nd form, but when I save, after I want to exit the form, it tells me this as if I didn't save:
Capture d’écran 2018-05-30 à 10.25.53.png
Though it is properly saved, because when I click OK on the pop up, and I search for the entry, it exists.
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

Add nuHasNotBeenEdited()

https://wiki.nubuilder.cloud/ ... BeenEdited

Code: Select all

if (nuFormType() == 'edit') {
    $("#contact_entreprise_id").val(window.ENTREPRISE_ID).change(); 
    nuHasNotBeenEdited();
}
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

I added it, but when I click on Save, I see the Save button turning from red to blue, and then quickly from blue to red again
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

marcvander wrote:I added it, but when I click on Save, I see the Save button turning from red to blue, and then quickly from blue to red again
I'm not able to reproduce it. I added this js to a form:

Code: Select all

if (nuFormType() == 'edit') {
    $("#some_field").val("test").change(); 
    nuHasNotBeenEdited();
}
Then I open the Edit Form, don't make any changes and click on "Save". The Save button doesn't turn to red.
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

But maybe it's because I enter the 2nd form from the 1st form right away, without passing through browse (in the button object, I put -1 as RECORD_ID to go to edit mode directly)

Here is my JS I have on the 1st form on which there is the button to go to the 2nd form with pre entered field:

Code: Select all

function nuSelectBrowse(e) {
    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    window.ENTREPRISE_ID = r;
    nuForm(nuGetProperty('form_id'), r, '', '', '1');   
}

if (nuFormType() == 'edit') {
    nuRunPHPHidden('EntrepriseNomAutoCompletion', 1);
}

function initAutoComplete() {
    $("#entreprise_nom").autocomplete({
        source: nuGetProperty('arrCompanyNames'),
        minLength: 1,
        select: function(event, ui) {
            $(event.target).val(ui.item.value).change();
        }
    });
}
And then here is what I have on the 2nd form:

Code: Select all

if (nuFormType() == 'edit') {
    $("#contact_entreprise_id").val(window.ENTREPRISE_ID).change();
    nuHasNotBeenEdited();
}

function nuSelectBrowse(e) {

    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    nuSetProperty('MAIN_FORM_RECORD_ID', r);
    nuForm(nuGetProperty('form_id'), r, '', '', '1');
    
}

if (nuFormType() == 'edit') {
    nuRunPHPHidden('ContactNomAutoCompletion', 1);
}

function initAutoComplete() {

    function setNames(ui) {

        setTimeout(function() {
            var selectVal = ui.item.value.toString();
            var a = selectVal.split(',')
            $('#contact_prenom').val(a[0]).change();
            $('#contact_nom').val(a[1]).change();
        }, 0);

    }

    $('#contact_prenom').autocomplete({
        source: nuGetProperty('arrContactNames'),
        minLength: 1,
        select: function(event, ui) {
            setNames(ui);
        }
    });

    $('#contact_nom').autocomplete({
        source: nuGetProperty('arrContactNames'),
        minLength: 1,
        select: function(event, ui) {
            setNames(ui);
        }
    });
}
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

Could it be that the autocomplete Plugin changes some fields (so that nuBuilder thinks they have been edited)?

Try adding another nuHasNotBeenEdited();

Code: Select all

function initAutoComplete() {

    function setNames(ui) {

        setTimeout(function() {
            var selectVal = ui.item.value.toString();
            var a = selectVal.split(',')
            $('#contact_prenom').val(a[0]).change();
            $('#contact_nom').val(a[1]).change();
        }, 0);

    }

    $('#contact_prenom').autocomplete({
        source: nuGetProperty('arrContactNames'),
        minLength: 1,
        select: function(event, ui) {
            setNames(ui);
        }
    });

    $('#contact_nom').autocomplete({
        source: nuGetProperty('arrContactNames'),
        minLength: 1,
        select: function(event, ui) {
            setNames(ui);
        }
    });

   nuHasNotBeenEdited();
}
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

Indeed that was it! Now it works. Thanks toms
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

Nice!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: #RECORD_ID# from a subform object

Unread post by admin »

.
Locked