Olá pessoal, tudo bem?
Eu to com um problema aqui meio cabuloso.
Eu estou utilizando o sanpopup quando uma determinada condição é satisfeita. Porém, esse popup deveria me retornar o valor do seu input, mas isso não está acontecendo. Depois de inúmeras alterações no código, até colocando fixo a resposta, ainda sim esta não está chegando para o meu JS principal.
No JS principal eu coloquei um console.log para imprimir o resultado, mas ele não vem.
Não era nem para ter o botão de confirmar ali, mas eu coloquei achando que esse poderia ser o problema. O certo era só de dar o Enter, ele fechar e retornar o valor inserido.
Além disso, às vezes acontece esse erro:
(antes de clicar no “Apontar”)
(depois de clicar no “Apontar”)
Trecho do código JS Popup
angular
.module("ApontamentoLeitorApp")
.controller("popupQtdApontadaController", [
"$scope",
"$popupInstance",
function (
$scope,
$popupInstance
) {
var self = this;
$popupInstance.$success = onClickConfirm;
setTimeout(function () {
init();
}, 2000);
function init() {
// Função keydown do campo de código de barraas
let inputQtdApontada = document.getElementById("inputQtdApontada");
inputQtdApontada.addEventListener("keydown", (e) => {
let key = e.which || e.keyCode;
//console.log(inputQtdApontada.value)
if (key === 13) {
// codigo da tecla enter ou tab
setTimeout(function () {
if (inputQtdApontada.value) {
console.log('chegou');
}
}, 50);
//inputQtdApontada.value = "";
}
});
}
function onClickConfirm () {
$popupInstance.$success({
resposta: 'teste'
});
}
},
]);
Trecho do código JS principal
if (resultado == "Não") {
return SanPopup.open({
title: "Quantidade Apontada",
templateUrl:
"html5/ApontamentoLeitor/popup/popupQtdApontada.tpl.html",
controller: "popupQtdApontadaController",
controllerAs: "ctrl",
type: "brand",
size: "alert",
grayBG: true,
okBtnLabel: i18n("Apontar"),
showBtnNo: false,
showIconClose: false,
}).result.then(function (result) {
console.log(result);
});
Código principal completo
angular
.module("ApontamentoLeitorApp", ["snk"])
.controller("ApontamentoLeitorController", [
"$scope",
"$rootScope",
"ObjectUtils",
"SkApplicationInstance",
"ServiceProxy",
"NumberUtils",
"MessageUtils",
"i18n",
"SanPopup",
"SkApplicationInstance",
"DatasetObserverEvents",
function (
$scope,
$rootScope,
ObjectUtils,
SkApplicationInstance,
ServiceProxy,
NumberUtils,
MessageUtils,
i18n,
SanPopup,
SkApplicationInstance,
DatasetObserverEvents
) {
let self = this;
setTimeout(function () {
init();
}, 2000);
function init() {
// Função keydown do campo de código de barraas
let inputCodBarra = document.getElementById("inputBarras");
inputCodBarra.addEventListener("keydown", (e) => {
let key = e.which || e.keyCode;
if (key === 13) {
// codigo da tecla enter ou tab
setTimeout(function () {
if (inputCodBarra.value) {
console.log(inputCodBarra.value);
let codbarras = inputCodBarra.value;
let params = { CODBARRAS: codbarras };
ServiceProxy.callService(
"[email protected]",
params
).then((response) => {
let resultado = ObjectUtils.getProperty(
response,
"responseBody.response"
);
if (resultado == "Não") {
return SanPopup.open({
title: "Quantidade Apontada",
templateUrl:
"html5/ApontamentoLeitor/popup/popupQtdApontada.tpl.html",
controller: "popupQtdApontadaController",
controllerAs: "ctrl",
type: "brand",
size: "alert",
grayBG: true,
okBtnLabel: i18n("Apontar"),
showBtnNo: false,
showIconClose: false,
}).result.then(function (result) {
console.log(result);
});
//MessageUtils.showAlert('Qtd Apontada', 'É necessário apontar quantidade.')
}
console.log("log 1");
// TODO: Fazer com que a caixa de diálogo da qtdApontada esteja selecionada e
// ouvindo um evento com o mesmo intuito.
});
} else {
MessageUtils.showError(
"Erro",
"O campo do código de barras não pode ser vazio!"
);
}
inputCodBarra.value = "";
}, 50);
}
});
}
},
]);