Dropzone Replace Remove file prompt confirmation with Modal BS4 - modal-dialog

I have try to change the pront confirmation of dropzone with a modal confirmation from bootstrap with this code:
Modal:
<div class="modal inmodal fade" id="RemoveFileModal" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content animated bounceInRight">
<div class="modal-header errormdg">
<button type="button" class="close" data-dismiss="modal"><i class="fas fa-window-close text-white"></i><span class="sr-only">Close</span></button>
<h4 class="modal-title">Cuidado: Estas Intentando Remover un Archivo.</h4>
</div>
<div class="modal-body">
<p>
Por algún motivo el sistema detecto que intentaste Remover un Archivo, Ten en cuenta que el archivo removido no podrás subirlo al sistema.<br> Este aviso es para que tengas en cuenta que si aceptas el archivo que remueves no será guardado en la Aplicación.<br><br>
Presiona Aceptar para Remover el archivo y Salir de la pantalla.<br>
Presiona Cancelar para Regresar.<br>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-cls-error" id="outAceptar" data-dismiss="modal">Aceptar</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Cancelar</button>
</div>
</div>
</div>
</div>
and use this Script for dropzone to catch the remove file event and display the modal:
$('div.dropzone').each(function() {
$(this).dropzone({
autoProcessQueue: true,
url: "/",
maxFilesize: window.SIS.uploadFiles.size,
maxFiles: window.SIS.uploadFiles.max,
acceptedFiles: 'application/pdf, image/jpeg, image/jpg, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
dictDefaultMessage: "<strong>Coloque los archivos Aqui. </strong></br> (Peso Maximo 2Mb, Se Aceptan los Siguientes Formatos: jpg, pdf, xls, xlsx.)",
addRemoveLinks: true,
dictCancelUpload: 'Cancelar Subida',
dictRemoveFile: 'Quitar Archivo',
clickable: true,
init: function() {
this.on("removedfile", function(data) {
var IsRemove = false;
$('#RemoveFileModal').modal('toggle').on('click', '#outAceptar', function(e) {
IsRemove = true;
});
return IsRemove;
});
},
});
});
the Main problem is that toogle modal not stop the remove file event to catch if user click "aceptar" or "cancelar". spanish option of accept and cancel.
the script show the modal but continue remove file in background.
Update
i have try with this but not work:
removedfile: function(file) {
$('#RemoveFileModal').modal('toggle').on('click', '#outAceptar', function(e) {
//myDropzone.removeFile(file);
return true;
});
$('#RemoveFileModal').modal('toggle').on('click', '#outCancelar', function(e) {
return false;
});
},

Using the removed file event is a good way:
// Called whenever a file is removed.
removedfile: function removedfile(file) {
$('#yourModalId').modal({
backdrop: 'static',
keyboard: false
})
$('#yourModalDeleteButton').click({file: file, self: this}, removeFile);
function removeFile(event)
{
$('#yourModalId').modal('hide');
// user confirmed , remove your file
}
},
As u can see I am passing the file object and this to my function because you will need atleast file object to remove the file. (Maybe not this it depends on how you handle file removal).

Related

i want to trigger the script automatically, without havin to click out of the input neither pressing enter

<!-- Adicionando Javascript -->
<script>
function limpa_formulário_cep() {
//Limpa valores do formulário de cep.
document.getElementById('rua').value=("");
document.getElementById('bairro').value=("");
document.getElementById('cidade').value=("");
document.getElementById('uf').value=("");
document.getElementById('ibge').value=("");
}
function meu_callback(conteudo) {
if (!("erro" in conteudo)) {
//Atualiza os campos com os valores.
document.getElementById('rua').value=(conteudo.logradouro);
document.getElementById('bairro').value=(conteudo.bairro);
document.getElementById('cidade').value=(conteudo.localidade);
document.getElementById('uf').value=(conteudo.uf);
document.getElementById('ibge').value=(conteudo.ibge);
} //end if.
else {
//CEP não Encontrado.
limpa_formulário_cep();
alert("CEP não encontrado.");
}
}
function pesquisacep(valor) {
//Nova variável "cep" somente com dígitos.
var cep = valor.replace(/\D/g, '');
//Verifica se campo cep possui valor informado.
if (cep != "") {
//Expressão regular para validar o CEP.
var validacep = /^[0-9]{8}$/;
//Valida o formato do CEP.
if(validacep.test(cep)) {
//Preenche os campos com "..." enquanto consulta
webservice.
document.getElementById('rua').value="...";
document.getElementById('bairro').value="...";
document.getElementById('cidade').value="...";
document.getElementById('uf').value="...";
document.getElementById('ibge').value="...";
//Cria um elemento javascript.
var script = document.createElement('script');
//Sincroniza com o callback.
script.src = 'https://viacep.com.br/ws/'+ cep + '/json/?
callback=meu_callback';
//Insere script no documento e carrega o conteúdo.
document.body.appendChild(script);
} //end if.
else {
//cep é inválido.
limpa_formulário_cep();
alert("Formato de CEP inválido.");
}
} //end if.
else {
//cep sem valor, limpa formulário.
limpa_formulário_cep();
}
};
</script>
<html>
<head>
<title>ViaCEP Webservice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<!-- Inicio do formulario -->
<form method="get" action=".">
<label>Cep:
<input name="cep" type="text" id="cep" value="" size="10" maxlength="9"
onblur="pesquisacep(this.value);" /></label><br />
<label>Rua:
<input name="rua" type="text" id="rua" size="60" /></label><br />
<label>Bairro:
<input name="bairro" type="text" id="bairro" size="40" /></label><br />
<label>Cidade:
<input name="cidade" type="text" id="cidade" size="40" /></label>
<br />
<label>Estado:
<input name="uf" type="text" id="uf" size="2" /></label><br />
<label>IBGE:
<input name="ibge" type="text" id="ibge" size="8" /></label><br />
</form>
Guys this script runs fine, as you can see here : https://codepen.io/RafaMenegassi/pen/GRrMBLm the thing is when i type for example 00000-000 this numbers of numbers i want to trigger the script automatically, without havin to click out of the input neither pressing enter.
https://viacep.com.br/exemplo/javascript/
At the top of your html page, do this:
<body onload=“limpa_formulário_cep()”> ... ... (rest of your html and JavaScript code)
When the page loads, this function SHOULD run

Symfony 3.4 and Modal Form Validation

I'm working in a Symfony 3.4 project with modal forms, thanks to RaresModalBundle this part is super easy to implement. My problem!?!? The constraint validation of the forms don't work because I can´t find a way to keep modal open or reopen it with the errors.
I read many articles and I can't find a robust solution. Around one week I find that jquery has a library call jqueryvalidation that help to validate forms but the examples I read and analize don't work so far in my project... the modal still close when I click the submit button without the correct validation.
But if I click outside de modal I can see the validator working, the problem remains in the subtmit button... here are the code of the controller and the modal:
/**
* Función encargada de generar el formulario para agregar un nuevo depósito.
*
* Se autorizan métodos GET y POST. El primero para acceder al formulario y el segundo para
* recibir el mismo.
*
* #Route("/agregar", name="agregar_depositos", methods={"GET", "POST"})
*
* #param Request $request
* #return RedirectResponse|Response
*/
public function agregarDepositos(Request $request)
{
$deposito = new Deposito();
$form = $this->createForm('AppBundle\Form\DepositoType', $deposito);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($deposito);
try {
$em->flush();
$this->addFlash('success', 'El depósito '.$deposito->getNombre().' ha sido insertado correctamente.');
}catch (DBALException $e){
$this->addFlash('error', 'El depósito '.$deposito->getNombre().' ya existe en la base de datos.');
};
return new ModalRedirectResponse($this->generateUrl('listar_depositos'));
}
return $this->render('registro/deposito/agregar.html.twig', array(
'deposito' => $deposito,
'form' => $form->createView(),
));
}
{% extends '#RaresModal/baseModal.html.twig' %}
{% block modalContent %}
{{ form_start(form, {'action': path('agregar_depositos')}) }}
<div class="modal-header">
<h5 class="modal-title m-0 font-weight-bold text-secondary"><i class="fas fa-fw fa-share-square"></i> Agregar Depósito</h5>
</div>
<div class="modal-body">
<div class="input-group mb-3" style="padding-top: 15px">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="far fa-fw fa-building"></i></span>
</div>
{{ form_widget(form.nombre) }}
</div>
</div>
<div class="modal-footer">
<div>
<button type="submit" class="btn btn-primary btn-sm btn-icon-split">
<span class="icon text-white-50">
<i class="fas fa-save"></i>
</span>
<span class="text">Guardar</span>
</button>
</div>
<div>
<button type="button" class="btn btn-secondary btn-sm btn-icon-split" data-dismiss="modal">
<span class="icon text-white-50">
<i class="fas fa-times"></i>
</span>
<span class="text">Cancelar</span>
</button>
</div>
</div>
<script type="text/javascript">
$( document ).ready( function () {
$( "#deposito-form" ).validate( {
rules: {
'appbundle_deposito[nombre]': {
required: true,
minlength: 3
}
},
messages: {
'appbundle_deposito[nombre]': {
required: "Este campo es obligatorio.",
minlength: "Este campo debe contener 3 o más caracteres."
}
},
errorElement: "em",
errorPlacement: function ( error, element ) {
// Add the `invalid-feedback` class to the error element
error.addClass( "invalid-feedback" );
if ( element.prop( "type" ) === "checkbox" ) {
error.insertAfter( element.next( "label" ) );
} else {
error.insertAfter( element );
}
},
highlight: function ( element, errorClass, validClass ) {
$( element ).addClass( "is-invalid" ).removeClass( "is-valid" );
},
unhighlight: function (element, errorClass, validClass) {
$( element ).addClass( "is-valid" ).removeClass( "is-invalid" );
}
} );
} );
</script>
{{ form_end(form) }}
{% endblock %}
Sorry my english... BR...
Ok... after some additional search, and try and error of course, the solution for my problem is:
Add a class to the submit button. EG: createButtom
Add the following lines to the javascript block in the modal view:
$(".createButton").click(function(e) {
if (!$('#deposito-form').valid()) {
e.preventDefault()
}
});

Ionic Return value navigation on different view

I have a form view with an input text. When I click on this input, another view is opened.
In this view, there are an input search and a list. The list change when I change a text from the input search.
I want when I click one item of the list, this view gets closed and the input text change. But I don't know how I can do that.
Can you help me please?
the input text in my form view:
<div class="select-typeevent">
<ion-item nav-clear menu-close ui-sref="menu.setlocation">
<label class="padding">
Address:
</label>
</ion-item>
</div>
My searchview:
<ion-view view-title="Address" class="content">
<ion-content>
<h1>Address</h1>
<div class="bar bar-header item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input class="border-none" name="txtssearch" type="search" placeholder="Search" ng-model="addresssearch" ng-change="getGeocode(addresssearch)">
</label>
<button class="button button-clear" ng-click="addresssearch='';getGeocode(addresssearch)">
Annuler
</button>
</div>
<div class="list" >
<a ng-repeat="addr in addresslist" class="item" ng-click="setaddress(addr)">
{{addr.address}} {{addr.location}}
</a>
</div>
</ion-content>
</ion-view>
And the js:
'Use Strict';
angular.module('App').controller('setlocationController', function ($scope,$state, $cordovaOauth, $localStorage, $location, $http, $ionicPopup,$firebaseObject,$ionicHistory, Auth, FURL, Utils) {
$scope.getGeocode = function (addresssearch) {
$scope.geodata = {};
$scope.queryResults = {};
$scope.queryError = {};
$http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + addresssearch)
.then(function (_results) {
$scope.addresslist = [];
$scope.queryResults = _results.data.results;
console.log($scope.queryResults);
$scope.queryResults.forEach(function(result) {
$scope.addresslist.push({ 'address': result.formatted_address, 'location': result.geometry.location });
});
},
function error(_error){
$scope.queryError = _error;
})
};
// Here I want when I click one item of the list, this view gets closed and the input text of formview change.
$scope.setaddress = function (addr) {
$scope.setaddress = addr;
$ionicHistory.backView();
}
Why not using an $ionicModal:
$scope.getGeocode = function (addresssearch) {
...
$scope.modal.show();
}
Previously set the modal:
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
Where my-modal.html points to the template which shows geocode information.

view not refreshing after zend redirect

so what i am trying to do, is after the user submit some information, i make a call to a action call saveronda, to save the information on the database, after saving i want to redirect to another page, according to the firebug the html is correct, but the view isnt refreshing.
so here is the code
so in my /rondas/chooseronda ive got this
<span class="st-labeltext">Tags da ronda:</span>
<table id="toolbar2"></table>
<div id="ptoolbar2"></div>
<div class="clear" style="z-index: 670;"></div>
</div>
<div class="st-form-line" style="z-index: 680;">
<span class="st-labeltext">Nome da ronda:</span>
<input type="text" name="nomeronda" id="nomeronda">
<div class="clear" style="z-index: 670;"></div>
</div>
<div class="st-form-line" style="z-index: 680;">
<span class="st-labeltext">Tag Inicial:</span>
<select id="tagini" name="tagini">
</select>
<div class="clear" style="z-index: 670;"></div>
</div>
<div class="st-form-line" style="z-index: 680;">
<span class="st-labeltext">Tag Final:</span>
<select id="tagfim" name="tagfim">
</select>
<div class="clear" style="z-index: 670;"></div>
</div>
<div class="st-form-line" style="z-index: 680;">
<span class="st-labeltext">Ordem:</span>
<select id="ordem" name="ordem">
<option value="Sim">Sim</option>
<option value="Não">Não</option>
</select>
<div class="clear" style="z-index: 670;"></div>
</div>
<div class="button-box" style="z-index: 460;">
<input id="button" class="st-button" type="submit" value="Submit" name="button">
<input id="button2" class="st-clear" type="reset" value="Cancel" name="button">
</div>
when the user press the button submit i am making an ajax call to /rondas/saveronda and send some data, here is the code:
<script language = "Javascript">
$(document).ready(function() {
$("#button").click(function () {
/*
$.ajax({
url: '/rondas/saveronda',
type: 'POST',
data: {param1: param1, param2:param2 },
datatype: "json"
*/
//buscar o nome
/*var nomeronda=$("#nomeronda").val();
//buscar a ordem
var ordem=$("#ordem").val();
//tag inicial e tag final
var taginicial=$("#tagini").val();
var tagfinal=$("#tagfim").val();
if(taginicial==tagfinal)
{
alert("a tag inicial não pode ser a mesma que a tag final");
}
else
{
var tags="";
//var allRowsOnCurrentPage = $('#toolbar2').getDataIDs();
var ids = $("#toolbar2").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++)
{
var rowId = ids[i];
var rowData = $('#toolbar2').jqGrid ('getRowData', rowId);
tags=tags+rowData.id_tag.toString()+' ';
}*/
$.ajax({
url: '/rondas/saveronda',
type: 'POST',
data: {param1: "sasa"},
datatype: "json"
});
//}
});
});
</script>
in this case i am sending param1 with the value "sasa", and through firebug i am detecting the post to the /rondas/saveronda.
after saving the data i want to redirect the user to /rondas/list, so i have been trying different solution
public function saverondaAction()
{
// action body
/*
if($this->_request->isXmlHttpRequest())
{
$param1 = $this->_request->getParam('param1');
$param2 = $this->_request->getParam('param2');
$param3 = $this->_request->getParam('param3');
$param4 = $this->_request->getParam('param4');
$param5 = $this->_request->getParam('param5');
$rondasModel= new Application_Model_Ronda();
$this->_forward('list', 'rondas');
}
*
*/
$this->_helper->redirector->gotoRoute(
array(
'controller' => 'rondas',
'action' => 'list'
)
);
}
or using redirect or forward..
none have worked, the view is still the /rondas/choosetags and not /rondas/list
what is my error...
thanks in advance..
Your initial view is /rondas/chooseronda when user press submit you make ajax call to /rondas/saveronda and send some data to it. Now if this is successful you want to redirect from the initial page (/rondas/chooseronda) to /rondas/list.
If the redirect code written in action /rondas/saveronda is not working, then you could return a success message back to initial view (/rondas/chooseronda), there you'll need to detect the success message in jQuery ajax code. If successful, put the redirect jQuery code, that will redirect it to /rondas/list.

Unexpected event using .not() jquery selector

I am showing a hidden menu when user clicks on an arrow (.userArrow) and I hide it when user clicks outside the container (.menuTrigger)
<div class="box">
<div class="menuTrigger fRight">
<span class="userArrow ">filtrar ▾</span>
<ul class="userOptionsUl dropdownMenu" style="display: none;">
<li><input type="text"></li>
</ul>
</div>
</div>
Javascript
$(function() {
/* el dropdown del dock*/
$('.menuTrigger .userArrow').click(function(e) {
e.preventDefault();
$(this).parent().find('.dropdownMenu').show();
e.stopPropagation();
});
$('body').not('.menuTrigger').click(function() { /* cambiar por la otra clase que tiene*/
$('.dropdownMenu').hide();
console.log('yo lo he escondido');
});
});
http://jsfiddle.net/5VQXg/
My problem here is that when user clicks to show the hidden menu and then clicks to type into the input. The menu is hidden.
The thing that all clicks are being inside .menuTrigger (or childs)
Question is, why $('body').not('.menuTrigger').click() when all clicks are being in childs of this container?
What your code is doing is filtering out any body element with a class of menuTrigger, which doesn't exist.
What you actually need to do is check if the element that was clicked (e.target) is inside of menuTrigger and then don't run the code if it is:
$('body').click(function(e) { /* cambiar por la otra clase que tiene*/
// If the clicked element is not inside menuTrigger div hide the menu
if (!$(e.target).closest('.menuTrigger').length) {
$('.dropdownMenu').hide();
console.log('yo lo he escondido');
}
});
http://jsfiddle.net/5VQXg/3/