Call JS function within modal

4

I have an event where a modal is displayed, in it I want to call a function validateEmail but I can not.

validateEmail: function(email) {
        var re = /^(([^<>()[\]\.,;:\[email protected]\"]+(\.[^<>()[\]\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    },
    events: {
        'onSwitchChange #servicos input.switch': function (evt) {
           (...)         
        },'onSwitchChange #users input.switch' : function(evt){
           (...)
        },
        'click #UserView button#viewas': function (evt) {
            (...)
        }, 'click button#update' : function(evt){
            evt.stopImmediatePropagation();
            var $me = $(evt.currentTarget);
            var tpl = Handlebars.compile($("#tpl-instancia-edit").html());
            var cat = $me.data('categoria');
            var dono = $me.data('dono');
            var id = $me.data('id');

            var $modal = $(tpl()).modal();

            $modal.show(function (evt){
                (...)
            });


              $modal.on('click', '#salvar', function(){
                evt.stopImmediatePropagation();
               //chamar funcao aqui
               alert(this.validateEmail($('input[id=donoUpdate]').val()));

                (...)
                }
            });

            });
        },
    
asked by anonymous 23.02.2015 / 18:24

1 answer

4
 'click button#update' : function(evt){
               (...)        

                $modal.show(function (evt){
                    (...)
                });

                validateEmail = function(email) {
                    var re = /^(([^<>()[\]\.,;:\[email protected]\"]+(\.[^<>()[\]\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                    return re.test(email);
                }

                $modal.on('click', '#salvar', function () {
                    evt.stopImmediatePropagation();

                    if (validateEmail($('input[id=donoUpdate]').val()) != false) {
                    (...)
                });

            },
    
23.02.2015 / 19:16