Page 2 of 2

Re: #RECORD_ID# from a subform object

Posted: Tue May 29, 2018 9:15 pm
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(); 
}

Re: #RECORD_ID# from a subform object

Posted: Wed May 30, 2018 10:30 am
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.

Re: #RECORD_ID# from a subform object

Posted: Wed May 30, 2018 11:08 am
by toms
Add nuHasNotBeenEdited()

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

Code: Select all

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

Re: #RECORD_ID# from a subform object

Posted: Wed May 30, 2018 11:23 am
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

Re: #RECORD_ID# from a subform object

Posted: Thu May 31, 2018 10:39 am
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.

Re: #RECORD_ID# from a subform object

Posted: Thu May 31, 2018 11:33 am
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);
        }
    });
}

Re: #RECORD_ID# from a subform object

Posted: Thu May 31, 2018 11:46 am
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();
}

Re: #RECORD_ID# from a subform object

Posted: Thu May 31, 2018 3:13 pm
by marcvander
Indeed that was it! Now it works. Thanks toms

Re: #RECORD_ID# from a subform object

Posted: Thu May 31, 2018 8:46 pm
by toms
Nice!

Re: #RECORD_ID# from a subform object

Posted: Sat Jun 02, 2018 1:54 am
by admin
.