Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Set hash variable from modal window

Post Reply
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Set hash variable from modal window

Unread post by Tinka »

Hi guys

I have a main form 1, and open form 2 from a button by OpenFormInFrame.
I want to send the new RECORD_ID back from the modal window (new record table 2) to form 1 as a preset value for a lookup.

I can update a field on the form in the modal window with the RECORD ID by using nuSetHash and nuGetHash in the AFTERSAVE php code, but it seems that the hash variable is not available to the form 1 as soon as I close the modal window (manually or by nuRemoveModal).

Code: Select all

//update field in many-to-many link table

$id = nuID();
$sql = "
INSERT INTO transcr_geneMMlink (transcr_gene_id, gene_idFK, transcr_idFK, comm)
VALUES ('$id','#gene_idFK#', '#RECORD_ID#', 'auto from primer') 

";

nuRunQuery($sql);
]$js = "
     alert('Transcript saved succesfully!');
     nuSetHash('trans','#RECORD_ID#');
var tr = nuGetHash('trans');
alert(tr);
    $('#transid').val(tr);
    nuRemoveModal();
$('#pri_transidFK').val(nuGetHash('trans'));
";

nuAddJavascript($js);

How can I send data back to form 1 (without reloading since the record on form 1 has not been saved yet).

Regards, Tinka
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Set hash variable from modal window

Unread post by admin »

Tinka,

You could try this..

Code: Select all

	$('#fieldId', window.parent.document).val(newValue);
Steven
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Re: Set hash variable from modal window

Unread post by Tinka »

Steven,

thank you for your fast reply and your code worked!

But because I want a default value for a lookup I had to set both the field and the code field in the lookup from the modal windows AfterSave php.
Otherwise the code field would be populated, but when trying to save the form would not recognize the mandatory lookup as being populated (I am not using the description field).
I first thought I needed some .change code that mimicks clicking on the lookup arrow.

Code: Select all

$js = "
    alert('Transcript saved succesfully!');

    $('#pri_transidFK', window.parent.document).val('#RECORD_ID#');
    $('#codepri_transidFK', window.parent.document).val('#trans_name#');

    nuRemoveModal();
";

nuAddJavascript($js);
BR, Tinka
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Set hash variable from modal window

Unread post by admin »

Tinka,

Maybe add..

Code: Select all

$('#pri_transidFK', window.parent.document).change();
Steven
Post Reply