Calling JS function inside modal

Asked

Viewed 831 times

4

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

validateEmail: function(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[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()));

                (...)
                }
            });

            });
        },
  • [SOLVED]Just declare the function within the event

  • You can post this as an answer?

1 answer

4


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

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

                validateEmail = function(email) {
                    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[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) {
                    (...)
                });

            },

Browser other questions tagged

You are not signed in. Login or sign up in order to post.