Set hash variable from modal window

Set hash variable from modal window

Postby Tinka » Wed Feb 24, 2016 6:01 pm

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
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Set hash variable from modal window

Postby admin » Thu Feb 25, 2016 2:05 pm

Tinka,

You could try this..

Code: Select all
   $('#fieldId', window.parent.document).val(newValue);


Steven
admin
Site Admin
 
Posts: 3234
Joined: Mon Jun 15, 2009 9:53 am

Re: Set hash variable from modal window

Postby Tinka » Thu Feb 25, 2016 7:39 pm

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
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Set hash variable from modal window

Postby admin » Thu Mar 17, 2016 1:32 pm

Tinka,

Maybe add..

Code: Select all
$('#pri_transidFK', window.parent.document).change();


Steven
admin
Site Admin
 
Posts: 3234
Joined: Mon Jun 15, 2009 9:53 am


Return to General