We have a search screen that works like this: There is a main screen. In it a button calls the search screen. This screen loads into a IFrame
that is within a Modal jquery-ui(Dialog)
. In this screen (search) I select some filters and clicking the search button opens a grid with the search result. Well, when I select a CPF or No. of Record, for example, it closes the screen and on the original caller page, the Textbox
are then filled with those values. What is going on. This search screen was previously developed within ShowModalDialog
. For this reason, it only works on IE(Modo Modal)
. No Chrome
it goes up normally, but not in a Modal way, which is why the company wants it to be validated in Chrome as well, but maintaining the functionality that exists in IE today. So, we start with a jquery
solution, for now to meet this specification, but the problem is that. Even clicking does not give any error, but nothing happens. The survey does not complete. Someone told me to switch to ajax
and see how it works, but I wonder if Dialog
jquery
can do.
See the screen below. When you click on contract, the Modal should be closed and on the background screen, the Contract field should be completed and the field next to it (ready only) should be filled with the Name.
Whenyouclickonthecontractorname,anyonewhohasa"link" is called a javascript () function and it closes Dialog and populates the bottom screen (calling page). See the function below:
function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
<%if trim(strAction) = "" then %>
//ABRIU POPUP
var txt_chamada = '';
try {
var oMyObject = window.dialogArguments;
txt_chamada = "oMyObject";
var aux = oMyObject.document;
} catch (e) {
txt_chamada = "window.parent.opener";
}
try{
//COD_TS_CONTRATO
<%if trim(txt_nome_campo_cod_ts)<>"" then %>
var ocod_ts_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod_ts%>");
<%else%>
var ocod_ts_contrato = eval(txt_chamada + ".document.form01.cod_ts_contrato");
<%end if %>
if (ocod_ts_contrato != null )
ocod_ts_contrato.value = cod_ts_contrato;
//NUM_CONTRATO
<%if trim(txt_nome_campo_cod)<>"" then%>
var onum_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod%>");
<%else%>
var onum_contrato = eval(txt_chamada + ".document.form01.num_contrato");
<%end if %>
if (onum_contrato != null )
onum_contrato.value = num_contrato;
//NOME_CONTRATO
<%if trim(txt_nome_campo_desc)<>"" then%>
var onome_entidade = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_desc%>");
<%else%>
var onome_entidade = eval(txt_chamada + ".document.form01.nome_contrato");
<%end if%>
if (onome_entidade != null )
onome_entidade.value = nome_entidade;
<%if trim(funcao_executar) <> "" then%>
try{
var aux = eval(txt_chamada+".<%Response.write funcao_executar%>");
}catch(e){
window.returnValue = 'window.<%Response.write funcao_executar%>';
}
<%end if%>
<%if ucase(indsubmit) = "TRUE" then%>
eval(txt_chamada + ".document.form01.submit()");
<%else %>
//Somente joga o Focus se o campo existir, e estiver desabilitado
if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true)
onum_contrato.focus();
<%end if%>
}catch(e){
//COD_TS_CONTRATO
<%if trim(txt_nome_campo_cod_ts)<>"" then %>
var ocod_ts_contrato = eval(txt_chamada + ".<%Response.write txt_nome_campo_cod_ts%>");
<%else%>
var ocod_ts_contrato = eval(txt_chamada + ".cod_ts_contrato");
<%end if %>
if (ocod_ts_contrato != null )
ocod_ts_contrato.value = cod_ts_contrato;
//NUM_CONTRATO
<%if trim(txt_nome_campo_cod)<>"" then%>
var onum_contrato = eval(txt_chamada + ".<%Response.write txt_nome_campo_cod%>");
<%else%>
var onum_contrato = eval(txt_chamada + ".num_contrato");
<%end if %>
if (onum_contrato != null )
onum_contrato.value = num_contrato;
//NOME_CONTRATO
<%if trim(txt_nome_campo_desc)<>"" then%>
var onome_entidade = eval(txt_chamada + ".<%Response.write txt_nome_campo_desc%>");
<%else%>
var onome_entidade = eval(txt_chamada + ".nome_contrato");
<%end if%>
if (onome_entidade != null )
onome_entidade.value = nome_entidade;
<%if trim(funcao_executar) <> "" then%>
/*try{
var aux = eval(txt_chamada+".<%Response.write funcao_executar%>");
}catch(e){
window.returnValue = 'window.<%Response.write funcao_executar%>';
}*/
var opener_document = oMyObject.ownerDocument;
var opener_window = opener_document.defaultView || opener_document.parentWindow;
try {
eval("opener_window." + "<%Response.write funcao_executar%>");
} catch (e) {
window.returnValue = "window." + "<%Response.write funcao_executar%>";
}
<%end if%>
<%if ucase(indsubmit) = "TRUE" then%>
eval(txt_chamada + ".submit()");
<%else %>
//Somente joga o Focus se o campo existir, e estiver desabilitado
if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true)
onum_contrato.focus();
<%end if%>
}
parent.self.close();
<%else %>
//ABRIU NORMAL ENTAO DAR SUBMIT
document.form01.cod_ts_contrato.value = cod_ts_contrato;
document.form01.num_contrato.value = num_contrato;
document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
document.form01.submit();
<%end if %>
}
I started making the changes and see the following. In the code piece below, in the first alert () I have the value of the variable, already in the second it is not called. I believe he gets lost in this situation:
.document.form01.<%Response.write txt_nome_campo_cod_ts%>");
I think I should switch to document.getElementsByName()
. I'm trying to make the change suggested by TobyMosque, but I confess I'm having some difficulty understanding, but I think it's the way.
try{
alert(cod_ts_contrato);
//COD_TS_CONTRATO
<%if trim(txt_nome_campo_cod_ts)<>"" then %>
var ocod_ts_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod_ts%>");
<%else%>
var ocod_ts_contrato = eval(txt_chamada + ".document.form01.cod_ts_contrato");
<%end if %>
if (ocod_ts_contrato != null )
ocod_ts_contrato.value = cod_ts_contrato;
alert(cod_ts_contrato);
So it was with TobyMosque's help.
function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
<%if trim(strAction) = "" then %>
//ABRIU POPUP
var txt_chamada = '';
if (window.dialogArguments) {
txt_chamada = "window.dialogArguments";
} else if (window.parent.opener) {
txt_chamada = "window.parent.opener";
} else if (window.parent.frameElement) {
if (window.parent.frameElement.ownerDocument.defaultView) {
txt_chamada = "window.parent.frameElement.ownerDocument.defaultView";
} else {
txt_chamada = "window.parent.frameElement.ownerDocument.parentWindow";
}
}
try{
//COD_TS_CONTRATO
var janela = null;
if (window.dialogArguments) {
janela = window.dialogArguments;
} else if (window.parent.opener) {
janela = window.parent.opener;
} else if (window.parent.frameElement) {
var documento = window.parent.frameElement.ownerDocument
var janela = documento.defaultView || documento.parentWindow;
}
if (janela) {
var txt_nome_campo_cod_ts = "<%= trim(txt_nome_campo_cod_ts) %>" || "cod_ts_contrato";
var txt_nome_campo_cod = "<%= trim(txt_nome_campo_cod) %>" || "num_contrato";
var ocod_ts_contrato = janela.document.form01[txt_nome_campo_cod_ts];
var onum_contrato = janela.document.form01[txt_nome_campo_cod];
// var onum_contrato = janela.document.getElementsByName(txt_nome_campo_cod);
}
// //NUM_CONTRATO
}catch(e){
// Aqui código do Catch. Retirei para não ficar grande a edição.
}
parent.self.close();
$("#dialog1", janela).dialog("close");
<%else %>
//ABRIU NORMAL ENTAO DAR SUBMIT
document.form01.cod_ts_contrato.value = cod_ts_contrato;
document.form01.num_contrato.value = num_contrato;
document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
document.form01.submit();
<%end if %>
}