Page 1 of 1

Set hash variable from modal window

Posted: Wed Feb 24, 2016 9:31 am
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

Re: Set hash variable from modal window

Posted: Thu Feb 25, 2016 5:35 am
by admin
Tinka,

You could try this..

Code: Select all

	$('#fieldId', window.parent.document).val(newValue);
Steven

Re: Set hash variable from modal window

Posted: Thu Feb 25, 2016 11:09 am
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

Re: Set hash variable from modal window

Posted: Thu Mar 17, 2016 5:02 am
by admin
Tinka,

Maybe add..

Code: Select all

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